1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
serg [7]
2 years ago
9

Write a program whose input is an email address, and whose output is the username on one line and the domain on the second. Exam

ple: if the input is:
[email protected]

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" 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(),

main.cpp is a read only file

#include
#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*/ is the TODO file

#include
#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;
}
Computers and Technology
1 answer:
kirill115 [55]2 years ago
6 0

Answer:

1 void parseEmailAddress(string email, string& username, string& domain)

2 {

3   int found = email.find("@")

4   if (found > 0)

5   {  

6     username = email.substr(0, found);  

7      domain = email.substr(found+1, -1);

8   }

9   return;

10}

Explanation line by line:

  1. We define our function.
  2. We use an open curly bracket to tell the program that we are starting to write the function down.
  3. We apply the find method to the email variable that was passed by the main program. The find method tells us where is the "@" located within the email.
  4. We use an if statement to ensure that the value that we found is positive (The value is negative if an only if "@" is not in the email address).
  5. We use an open curly bracket to tell the program that we are starting to write inside the if statement.
  6. We apply the substr method to the email to take the username; it receives a start and an end value, this allows us to take from the beginning of the email (position 0) until the "@".  
  7. We apply the substr method to the email to take the domain; it receives the position of the "@" character plus one to take the first letter after the "@" and a minus-one representing the last character on the email.
  8. We use a closing curly bracket to tell the program that the if statement has finished.
  9. We return nothing because we are using reference parameters, which means that the memory positions of username and domain are going to be filled by our parseEmailAddress function and the main function can access those values directly.
  10. We use a closing curly bracket to tell the program that the function has finished.
You might be interested in
When creating envelopes, how will you adjust the layout?
Burka [1]
It D because I hade this too so it is D
4 0
2 years ago
Read 2 more answers
What is the correct order of precedence of the mathematical operators?
LenaWriter [7]
A common technique for remembering the order<span> of </span>operations<span> is the abbreviation "PEMDAS", which is turned into the phrase "Please Excuse My Dear Aunt Sally". It stands for "Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction".</span>
7 0
3 years ago
What is the process called that occurs when you start up your computer? A Download B Restore C Boot D Copy
inn [45]
Starting up your computer can also be referred to as "booting up" therefore, the answer is c
8 0
3 years ago
Read 2 more answers
20 points!!!!! Plz answer quickly
Elena L [17]

Answer:

other words are not clear

3 0
2 years ago
What are the programs in a computer​
stealth61 [152]

Answer:

Computer skills examples

Operating systems  

Office suites  

Presentation software

Spreadsheets  

Accounting software

Explanation:

A program is a set of ordered operations for a computer to do in computing. The program in the modern computer described by John von Neumann in 1945 has a one-at-a-time series of instructions that the computer follows. Typically, the application is saved in a computer-accessible storage location.

4 0
2 years ago
Other questions:
  • What are the meaning master files<br>​
    8·1 answer
  • Create the tables and appropriate constraints based on the following ER diagram. Use appropriate data types. Note that the size
    7·1 answer
  • Window frame will expand to fill the entire desktop when you
    12·1 answer
  • ______ is a customer-facing CRM application.<br><br> FAQ<br><br> Search<br><br> SFA<br><br> E-mail
    6·1 answer
  • (4 points.) Write an algorithm (i.e., step-by-step instructions) via which someone could walk or drive from some origin to some
    8·1 answer
  • What term is used to describe our connection with eachother through technology
    6·1 answer
  • Question # 1
    12·2 answers
  • Saujani describes that women are highly underrepresented in STEM careersShe attributes this to women needing more confidence. Wh
    13·1 answer
  • Choose the best collection for each situation.
    8·1 answer
  • Which of the following is the system of rules and structure governing
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!