Question: C++ please Write a program whose input is an email address, and whose output is the username on one line and the domain on the
C++ please
Write a program whose input is an email address, and whose output is the username on one line and the domain on the second. Example: if the input is:
pooja@piazza.com
Then the output is
username: pooja domain: piazza.com
The main program is written for you, and cannot be modified. Your job is to write the function parseEmailAddress defined in "util.cpp"; you can select this file from the drop-down list above the editing window. The function is called by main() and passed an email address, and parses the email address to obtain the username and domain. These two values are returned via reference parameters. Hint: use the string functions .find() and .substr(), documented here. Assume the program is given a valid email address, i.e. containing a non-empty username and domain separated by the '@' character.
#
Working with zylabs
One way to test your work is in "Develop mode". Click "Run my program", then click anywhere in the terminal window and enter your test input. Your program output will be shown in the terminal window
The other way to test your work is to switch to "Submit mode", and click "Submit for Grading". This will test your program against the provided test cases, and report your score (0..100). You have unlimited submissions on this exercise; the system records your highest score across all submissions.
Some background on the zyLabs programming environment. Between submissions, the zyLab system does not save your work. For example, if you write your program and then close the browser, when you come back your program will be gone. For this reason, save your work in a separate document using an editor or word processor. Each time you submit your work is saved, but nothing is saved until the first submission, and nothing is saved between submissions.
Auto-grading systems are great in giving immediate feedback, but the trade-off is they are inflexible. You have to read the problem description very carefully, and do exactly what it says. If your answer differs in any way e.g. an extra space in the output it is marked as incorrect and your score on that test case is 0.
If your program is not working, switch to "Develop mode", add some output / debugging statements, and run.
main.cpp
// // HW #02-2: program to parse an email address and output username, domain. //
#include
using namespace std;
// function declaration: void parseEmailAddress(string email, string& username, string& domain);
int main() { string email, username, domain;
cout << "Please enter a valid email address> "; cin >> email; cout << endl; parseEmailAddress(email, username, domain); cout << "username: " << username << endl; cout << "domain: " << domain << endl;
return 0; }
util.cpp
/*util.cpp*/
#include
using namespace std;
// // parseEmailAddress: // // parses email address into usernam and domain, which are // returned via reference paramters. // void parseEmailAddress(string email, string& username, string& domain) { // // TODO: use .find() and .substr() // username = ""; domain = ""; return; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
