Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that reads in a list of first and last names of new employee

ID: 3767169 • Letter: W

Question

Write a C++ program that reads in a list of first and last names of new employees from an input data file named newhires.txt. The program should create a username and email address for each person. The username should be the first initial of the person’s first name and the last name. If the person’s first initial and last name doesn’t produce a username that is at least 6 characters, the program should add zeros to make it 6 characters. The email address consists of the username plus the following: @riaztrucking.com . The program should print the first name, the last name, the user name, and email address for each person to the output data file hiringdata.txt.

For example, assume the input file contained the following names

James Smith Ty Li

Then, the output data file should contain the following:

James Smith JSmith jsmith@riaztrucking.com

Ty Li TLi000 tli000@riaztrucking.com

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
#include <locale>

using namespace std;

int main()
{
   ifstream fin;
   ofstream fout;
   fin.open("newhires.txt");
   fout.open("hiringdata.txt");
   string first,last,username,email_id;
   int i,len;

   while(!fin.eof())
   {  
       email_id = "";
       fin>>first;
       fin>>last;
       username = first[0]+last;
       len = username.length();
       while(len<6){
           username = username+"0";
           len++;
       }
       for(i=0;i<len;i++)
       email_id += char(tolower(username[i]));
       email_id += "@riaztrucking.com";
       fout<<first<<" "<<last<<" "<<username<<" "<<email_id<<endl;
   }

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote