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 #include using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!