Read in a 2-character string from input into variable passwordStr. Declare a boolean variable isValid and set isValid to true if the following conditions are met: • passwordStr does not contain two of the same character. • For alphabetic characters, passwordStr does not contain two of the same letter (regardless of case). Otherwise, set isValid to false.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

confused on how to proceed

CHALLENGE
ACTIVITY
3.15.1: Character operations.
405150.2848768.qx3zqy7
Jump to level 1
Read in a 2-character string from input into variable passwordStr. Declare a boolean variable isValid and set isValid to true if the
following conditions are met:
• passwordStr does not contain two of the same character.
• For alphabetic characters, passwordStr does not contain two of the same letter (regardless of case).
Otherwise, set isValid to false.
Ex: If the input is 5&, then isValid is assigned with true, so the output is:
Valid password
Ex: If the input is Pp, then isValid is assigned with false, so the output is:
Invalid password
Note: Use getline(cin, passwordStr) to read the entire line from input into passwordStr.
1 #include <iostream>
2 #include <string>
3 #include <cctype>
4 using namespace std;
5
6 int main() {
7
8
9
10
11
12
13
14
15
16
Check
string passwordStr;
getline(cin, passwordStr);
bool isValid
true;
toupper(passwordStr.at (0) && toupper(passwordStr.at (1)));
isValid = false;
if (isValid) {
1
=
Next level
X 1: Compare output
To check if passwordStr does not contain two of the same character, regardless of case, the toupper() function can be used to
convert both characters to the uppercase version. Then, the two returned values are checked for equality. The tolower() function
can also be used.
Not all tests passed.
Output differs. See highlights below.
Input
Your output
5 &
Invalid password
2
Expected output Valid password
3
1
2
3
Transcribed Image Text:CHALLENGE ACTIVITY 3.15.1: Character operations. 405150.2848768.qx3zqy7 Jump to level 1 Read in a 2-character string from input into variable passwordStr. Declare a boolean variable isValid and set isValid to true if the following conditions are met: • passwordStr does not contain two of the same character. • For alphabetic characters, passwordStr does not contain two of the same letter (regardless of case). Otherwise, set isValid to false. Ex: If the input is 5&, then isValid is assigned with true, so the output is: Valid password Ex: If the input is Pp, then isValid is assigned with false, so the output is: Invalid password Note: Use getline(cin, passwordStr) to read the entire line from input into passwordStr. 1 #include <iostream> 2 #include <string> 3 #include <cctype> 4 using namespace std; 5 6 int main() { 7 8 9 10 11 12 13 14 15 16 Check string passwordStr; getline(cin, passwordStr); bool isValid true; toupper(passwordStr.at (0) && toupper(passwordStr.at (1))); isValid = false; if (isValid) { 1 = Next level X 1: Compare output To check if passwordStr does not contain two of the same character, regardless of case, the toupper() function can be used to convert both characters to the uppercase version. Then, the two returned values are checked for equality. The tolower() function can also be used. Not all tests passed. Output differs. See highlights below. Input Your output 5 & Invalid password 2 Expected output Valid password 3 1 2 3
14
15
16
17
18
19
20
21
22
23
24 }
Check
if (isValid) {
cout << "Valid password" << endl;
}
else {
cout << "Invalid password" << endl;
}
return 0;
1
Next level
X 1: Compare output
To check if passwordStr does not contain two of the same character, regardless of case, the toupper() function can be used to
convert both characters to the uppercase version. Then, the two returned values are checked for equality. The tolower() function
can also be used.
Not all tests passed.
Output differs. See highlights below.
Input
Your output
Expected output
5 &
Invalid password
2
Valid password
3
Transcribed Image Text:14 15 16 17 18 19 20 21 22 23 24 } Check if (isValid) { cout << "Valid password" << endl; } else { cout << "Invalid password" << endl; } return 0; 1 Next level X 1: Compare output To check if passwordStr does not contain two of the same character, regardless of case, the toupper() function can be used to convert both characters to the uppercase version. Then, the two returned values are checked for equality. The tolower() function can also be used. Not all tests passed. Output differs. See highlights below. Input Your output Expected output 5 & Invalid password 2 Valid password 3
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education