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]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
Jabria are you smart
kiruha [24]

Answer:

A. YESSSSSS

Explanation:

8 0
2 years ago
Read 2 more answers
Write a method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(l
kifflom [539]

Answer:

The java program for the given scenario is shown below.

import java.util.*;

import java.lang.*;

public class Test

{

   //variables to hold the number, digits and sum of the digits

   //variable to hold number is assigned any random value

   static long num=123;

   static int sum=0;

   static int digit;

   static int s;

   //method to add digits of a number

   public static int sumDigits(long n)

   { do

       {

           digit=(int) (n%10);

           sum=sum+digit;

           n=n/10;

       }while(n>0);

       return sum;

   }

public static void main(String[] args) {

    s = sumDigits(num);

 System.out.println("The sum of the digits of "+num+ " is "+s);  }

}

OUTPUT

The sum of the digits of 123 is 6

Explanation:

1. The variables to hold the number is declared as long and initialized.

2. The variables to store the digits of the number and the sum of the digits are declared as integer. The variable, sum, is initialized to 0.

3. The method, sumDigits(), is defined which takes a long parameter and returns an integer value. The method takes the number as a parameter and returns the sum of its digits.

4. Inside method, sumDigits(), inside the do-while loop, the sum of the digits of the parameter is computed.

5. Inside main(), the method, sumDigits(), is called. The integer value returned by this method is stored in another integer variable, s.

6. The sum of the digits is then displayed to the console.

7. All the variables are declared outside main() and at the class level and hence declared static. The method, sumDigits(), is also declared static since it is to be called inside main().

8. In java, the whole code is written inside a class since java is a purely object-oriented language.

9. In this program, object of the class is not created since only a single class is involved having main() method.

10. The program can be tested for any value of the variable, num.

11. The file is saved as Test.java, where Test is the name of the class having main() method.

7 0
3 years ago
Pig Latin is ______ and fits very naturally in the pipeline paradigm while SQL is instead declarative.
alisha [4.7K]

Answer:

Option b) is correct

Explanation:

Pig Latin is a language game in which English words are altered either by adding a suffix or such kind of suffix can be created by adding a syllable (vocalic). For example, ''hello'' becomes ''ello-hay''.

Pig Latin is <u>procedural</u> and fits very naturally in the pipeline paradigm while SQL is instead declarative.

3 0
2 years ago
Telecommunications is the transmission of voice and video as well as data and usually implies transmitting a longer distance tha
saul85 [17]

Answer:

The correct answer to the following question will be "True".

Explanation:

  • Telecommunication seems to be the transmitting by cable, antenna, optical or other electromagnetic networks of signs, commands, letters, words, texts, pictures, and sounds, or knowledge of any kind.
  • This happens when the use of technologies involves the information exchange between participants in the conversation.

Therefore, the given statement is true.

6 0
2 years ago
I am trying to test out the software Classroom relay and I am just ask if there is any way kids can stop Classroom relay form se
Ratling [72]

Answer:

just don't share your screen in the class or if your a teacher just call them out

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which statement describes the word "iterative"?
    7·2 answers
  • A computer’s memory is composed of 8K words of 32 bits each. How many bits are required for memory addressing if the smallest ad
    10·1 answer
  • vulnerability is a feebleness which allows an attacker to condense a system's information assurance to security,is it true or fa
    14·1 answer
  • 次のうち、ビジネスレターに適したフォントとポイントサイズの選択はどれですか?<br> 私を助けてください!私はあなたを最高にブランコにします!
    12·2 answers
  • Which code must be included to use Turtle Graphics?
    14·2 answers
  • 3n - 12 = 5n - 2<br> how many solutions?
    15·1 answer
  • While using a web-based order form, an attacker enters an unusually large value in the Quantity field. The value he or she enter
    15·1 answer
  • Find the unknown quantities
    12·1 answer
  • Do you need a separate password for each slack channel
    13·1 answer
  • How to stop sharing location without them knowing imessage.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!