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
All of the following are true of using the database approach to managing data except Group of answer choices Decentralized manag
kolezko [41]

Answer:

Decentralized management of data

Explanation:

  • The database management approach is one approach based on the improved standard file solution with the use of DBMS and allows for the stimulus access of data with a large number of users.
8 0
2 years ago
If you ping a device, you are using the______protocol
meriva
Joystick..................:-)
6 0
3 years ago
A DFA is equivalent in power to an NFA. True False
sattari [20]

Answer: True

Explanation:

  Yes, the given statement is true that a DFA is equivalent to NFA in terms of power. For any type of NFA we can easily build an equal DFA so, the NFA are not much powerful as compared to DFA. Both NFA and DFA are characterized by a similar type of class.

DFA is a special case of NFA and They both defined in the same class of language. Each condition in the DFA get summarized by all the condition that the NFA has itself.

4 0
2 years ago
What is the most efficient<br> form of transportation we<br> have?
alisha [4.7K]

Answer:

The bicycle is a tremendously efficient means of transportation. In fact cycling is more efficient than any other method of travel--including walking! The one billion bicycles in the world are a testament to its effectiveness

Explanation:

6 0
2 years ago
Read 2 more answers
Suppose you are given a sequence that is described by a formula, starting at index n=0. If you need to change the starting index
Arisa [49]

Answer:

n+1

Explanation:

Given

n = 0 --- starting index

Required

Change the starting index to n = 1

We have:

n = 0

To change the starting index to k, we simply rewrite as:

n+k

<em>In this case; k=1; so, the starting index will be: </em>n+1<em />

3 0
3 years ago
Other questions:
  • . When you have multiple graphics positioned on a page, you can _______________ them so that they are a single graphic instead o
    9·1 answer
  • Most graphics software uses a process called pixel _________ to create new pixels by averaging the colors of nearby pixels.â
    6·1 answer
  • What is encyclopedia. Com considered to be?
    14·1 answer
  • Your supervisor has asked you to set up a RAID hard drive array in a tower system, which has a motherboard that uses the B360 ch
    10·1 answer
  • True or False? In a C++ floating-point constant, a decimal point is not required if exponential (E) notation is used
    13·1 answer
  • who will follow me on tiktok and like all my videos? if you do ill give branlist and give u a shoutout and you can enter my big
    15·1 answer
  • Will give 5 star and the mark brainleist
    11·2 answers
  • Which key doesn't relate to keyboard A:return key B :enrollment key C: delete key D:tab key
    9·2 answers
  • LIST THE 7 BEST PROGRAMMING MOVIES 2020-2021.
    9·1 answer
  • A Product Manager has been given responsibility for overseeing the development of a new software application that will be deploy
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!