Question

In C++ write a complete and correct x++ program that generates student email addresses and prints...

In C++

write a complete and correct x++ program that generates student email addresses and prints them to the screen based upon the data found in an input file, called students . txt. Each line of the space, followed by the student’s last name. Every email address is to be of the form [email protected]. In general, each username has four parts in this order: (i) the student; last name in lowercase letters; (ii) a number between 10- 99 generated at random for each student; (iii) the first character (in lowercase) in the student’s first name; and (iv) the letter x repeated until the username is of length 10. If any username defined above is longer than 10 characters in length, then only use the first 10 characters. For example, if the first seven lines of students. Txt were as shown below in the first column, then generated email addresses would be as shown be as shown below in the second column:

Hayden Christensen [email protected]

Donald Sutherland [email protected]

Kate Blanchett [email protected]

Neve Campbll [email protected]

Wayne Gretzky [email protected]

Justin Bieber [email protected]

Steve Jobs [email protected]

Hints:

(i) The header file includes useful function like tolower () and isspace (). Each of which takes a char as input.

(ii) You may use some string function discussed in class: at () , find () , length () , size () , and substr ().

(iii) Be carful with data types.

(iv) The header file includes a value returning function rand () that can be used to generate random integer numbers in the range [ 0 , RANd_MAX] where RAND_MAX is a very large integer , 32,767, for instance. To use this function, you should:

* Include in the header;

* Call the void faction srand (time(NULL)) at the beginning of you main () function to initialize the random generator; and

* Call rand () wherever you want a random integer number.

Please read the question before answering it and show the output Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for you:

#include <iostream>
#include <fstream>
using namespace std;
string tolower(string input)
{
string output = "";
for(int i = 0; i < input.length(); i++)
output += tolower(input[i]);
return output;
}
string appendOrTrim(string input)
{
string output = "";
for(int i = 0; i < 10 && i < input.length(); i++)
output += input.at(i);
for(int i = output.length()-1; i < 9; i++)
output += 'x';
return output;
}
int main()
{
ifstream fin;
string fileName;
//StudentNames.txt
cout<<"Enter the name of the file to read student names: ";
cin>>fileName;
fin.open(fileName);
srand(time(NULL));
string firstName, lastName, mailId, finalId;
while(!fin.eof())
{
fin>>firstName;
fin>>lastName;
mailId = tolower(lastName);
mailId += to_string(rand() % 90 + 10);
mailId += tolower(firstName.at(0));
finalId = appendOrTrim(mailId) + "@university.ca";
cout<<finalId<<endl;
}
}

And the output screenshot is:

Add a comment
Know the answer?
Add Answer to:
In C++ write a complete and correct x++ program that generates student email addresses and prints...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that generates and prints 24 random values using an array and the...

    C++ Write a program that generates and prints 24 random values using an array and the rand () function. Implement an algorithm to find the maximum and a minimum number of random numbers generated. Use the header "#include <ctime>", "#include <cstdlib>" in addition to the usual header: "#include <iostream>"

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • Write a C program to compute average grades for a course. The course records are in...

    Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • Can anyone help me with my C hw? Exercise 3 You will write a new program...

    Can anyone help me with my C hw? Exercise 3 You will write a new program that combines dynamically allocating an array and saving that array to a file. These are the tasks your program must perform Open an output file named "data.txt" and prepare it for writing in text mode o If the file handle is NULL, quit the program o By default, it is created and stored in the same directory as your source code file Prompt the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT