Question
Strings username1 and password1 are read from input. Complete the try block to output username1 followed by : Access granted with error checking: If the
Strings username1 and password1 are read from input. Complete the try block to output username1 followed by ": Access granted" with error checking:
If the first character of username1 is not a letter, throw a runtime exception with the message "User name must start with a letter".
If password1's length is < 7, throw a runtime exception with the message "Password is too short".
Ex: If input is Astrid asparagus, then the output is:
Astrid: Access granted
Ex: If input is !Maricruz asparagus, then the output is:
Error: User name must start with a letter
Ex: If input is Astrid leek, then the output is:
Error: Password is too short
Notes:
isalpha(username1[0]) returns true if the first character of username1 is a letter.
password1.length() returns the length of string password1.
#include
int main() { string username1; string password1;
cin >> username1; cin >> password1;
try {
/* Your code goes here */
} catch (runtime_error& excpt) { cout << "Error: " << excpt.what() << endl; }
return 0; }
c++ and pleasee please make it correct
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started