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
Get step-by-step solutions from verified subject matter experts
