Question
Strings yourUsername and yourDomain are read from input. Complete the try block to output Email: followed by yourUsername and yourDomain with error checking: If
Strings yourUsername and yourDomain are read from input. Complete the try block to output "Email: " followed by yourUsername and yourDomain with error checking:
If yourUsername's length is < 3 or > 10, throw a runtime exception with the message "User name's length must be between 3 and 10".
If yourDomain does not start with '@', throw a runtime exception with the message "Domain must start with '@'".
Ex: If input is Sahar @endive, then the output is:
Email: Sahar@endive
Ex: If input is Wo @endive, then the output is:
Error: User name's length must be between 3 and 10
Ex: If input is Sahar artichoke, then the output is:
Error: Domain must start with '@'
Notes:
yourUsername.length() returns the length of string yourUsername.
yourDomain[0] != ch returns true if the first character of yourDomain is not character ch.
#include
int main() { string yourUsername; string yourDomain;
cin >> yourUsername; cin >> yourDomain;
try {
/* Your code goes here */
} catch (runtime_error& excpt) { cout << "Error: " << excpt.what() << endl; }
return 0; }
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