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]
3 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]3 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 a computer or digital device is used as a storage device or in the facilitation of an offense, it is argued to be ____ to t
Katen [24]

Answer:

Incidental.

Explanation:

When a computer or digital device is used as a storage device or in the facilitation of an offense, it is argued to be incidental to the offense.

For instance, the list of customers used by human traffickers is considered to be generated through an incidental system.

8 0
2 years ago
// This class calculates a waitperson's tip as 15% of the bill public class DebugThree1 { public static void main(String args[])
DENIUS [597]

I added a decimal format to keep all decimals within the hundredths place. I also changed the calcTip method to void and the argument to a double. Void means the method doesn't return anything and changing bill to type double let's us pass numbers with decimals to the calcTip method. I hope this helps!

Download txt
4 0
3 years ago
PLS HELP ;CC
icang [17]

Answer:

a

early photographers who were first painters

Explanation:

The Rule of Thirds is a compositional technique which states that image painting, photograph, graphic design should be divided into nine equally proportioned boxes by creating a grid with two vertical and two horizontal lines. The rule of third helps in making the picture more attractive and balanced

The rule of thirds was first used in landscape paintings by painters as early as 1797.

5 0
3 years ago
What the benefits of folder when working with files
sasho [114]
It helps to keep things organized
3 0
3 years ago
Read 2 more answers
Which of the following identifies the patterns used for each data series in a chart?
Lady_Fox [76]
The answer is A)Legend.
7 0
3 years ago
Other questions:
  • For local travel addresses and street names should be
    14·1 answer
  • You are working on an excel table and realize that you need to add a row to the middle of your table. what is one way to do this
    12·1 answer
  • What part of the code is a signal for the function to execute and pass back a value?
    11·2 answers
  • How can you specify a page has the highest priority?
    7·1 answer
  • If you wish to sign out of your Microsoft account, tap or click ____ on the ribbon to open the Backstage view and then tap or cl
    10·1 answer
  • a rule that states each foreign key value must match a primary key value in the other relation is called the
    5·1 answer
  • In order for the image tag in an HTML file to function properly, the file named square.png must be located where?
    5·2 answers
  • Write a program that asks the user to enter two integer numbers X and Y. The program halves each number between X and Y then pri
    15·1 answer
  • An organization is developing an authentication service for use at the entry and exit ports of country borders. The service will
    10·1 answer
  • Most spyware programs are benign in that they do not perform malicious acts or steal data. group of answer choices true false
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!