C question Write a complete and correct C program that gener
C++ question
Write a complete and correct C++ program that generates student email address and prints them to the screen based upon the data found in an input file, called students.txt.each line of the input file corresponds to one student and consists of the students\'s first name, followed by one space, followed by the student\'s last name.every email address is be of the form general, each username has four parts in this order the student\'s last name in lowercase letters; a number between 10-99 generated at random for each student; the first character (in lowercase) in the student\'s first name; and 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 below in the second column:Solution
#include<bits/stdc++.h>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
ifstream file1(\"students.txt\");
string fname,lname;
string email_add=\"@uregina.ca\";
while(file1>>fname>>lname)
{
cout<<fname<<\" \"<<lname<<\" \";
lname[0]=tolower(lname[0]);
if(lname.length()<10)
{
int l=lname.length();
int r=random()%99+10;
lname=lname+to_string(r);
string firstLetter(1,tolower(fname[0]));
lname=lname+firstLetter;
string xxx=\"xxxxxxxxxx\";
lname=lname+xxx;
}
lname = lname.substr (0,10);
lname=lname+email_add;
cout<<lname<<endl;
}
return 0;
}
========================================
Output:
akshay@akshay-Inspiron-3537:~$ g++ -std=c++11 student.cpp
akshay@akshay-Inspiron-3537:~$ ./a.out
Hayden Christensen christense@uregina.ca
Donald Sutherland sutherland@uregina.ca
Kate Blanchett blanchett3@uregina.ca
Neve Campbell campbell53@uregina.ca
Wayne Gretzky gretzky82w@uregina.ca
Justin Bieber bieber89jx@uregina.ca
Steve Jobs jobs33sxxx@uregina.ca

