Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is what I have to do: Generate unique usernames based on first initial and last name. If a username is already taken, then add

This is what I have to do: Generate unique usernames based on first initial and last name. If a username is already taken, then add an increasing numeral to it.
a. Output the student name, username and ID to a second file +2
Example input file:
Smith, Mary
and later on there is
Smith, Michelle
Output to a file, maybe existingStudents.txt
Consider overloading the <<
It might look like:
Mary Smith,A0000001,msmith
Michelle Smith,A0000002,msmith2
(or msmith1 if you want - just as long as they are different. )
b. Create a way to read in the file above and set Student values. +2 Here, each student might be read in and the ID would be set explicitly.Consider overloading the >> operator
This is what I have so far: #include
#include "Prof.h"
#include "UnivMember.h"
using namespace std;
Professor:: Professor() : UnivMember()
{
username ="no userName" ;
pName = getUnivName(); //the private members of the base class (UnivMember) cannot be accessed by the derived class
pID = getUnivID();
}
Professor:: Professor(string emailName, Name profName, ID profID)
{
username = emailName;
pName = profName.getFirstName()+""+ profName.getLastName();
pID = profID.getfull();
}
Professor:: ~Professor(){}
void Professor:: PrintAll()
{
cout << "Name: "<< pName << endl;
cout << "Email: "<< username <<"@fordham.edu" << endl;
cout <<"ID: "<< pID << endl << endl;
}
void Professor:: setUsername(string emailName)
{
username = emailName;
}
void Professor:: setName(Name profName)
{
pName = profName.getFirstName()+""+ profName.getLastName();
}
void Professor:: setID(ID profID)
{
pID= profID.getfull();
}
string Professor:: getUsername()
{
return username;
}
string Professor:: getName()
{
return pName;
}
string Professor :: getID()
{
return pID;
}
ostream& operator<<(ostream& outs, const Professor& prof)
{
outs << "Name: "<< Prof.getName()<< endl;
outs << "Email: "<< prof.getUsername()<<"@fordham.edu
";
outs <<"ID: "<< prof.getID()<< endl;
return outs;
}
istream& operator>>(istream& ins, Professor& prof)
{
string fullName, username, numID;
getline(ins, fullName);
ins >> username >> numID;
return ins;
}
~#include
#include
#include
#include
#include
#include "Prof.h"
using namespace std;
string createUsername(Name profName)//function to create the username
{
string firstName = profName.getFirstName();
char firstInitial= firstName.at(0); //first inital of first name
tolower(firstInitial);
tolower(profName.getLastName().at(0));
string username = firstInitial + profName.getLastName();
return username;
}
int main()
{
ifstream infile; //will be reading from a file
ofstream outfile; //will be inputing into a file
string profName; //to parse the file - names of profs
string pEmail;
infile.open("CSProfNames.txt"); //file containing professor names
if(!infile.is_open())//testing to ensure that the file is open
{
cout << "File is not open." << endl;
exit (0);
}
vector profVector; //vector to hold the professors made
while(getline(infile, profName))
{
Name pName(profName);
ID pID;
pEmail = createUsername(pName);
Professor prof(pEmail, pName, pID);
profVector.push_back(prof); //adding the prof to the vector
}
outfile.open("existingProfessors.txt"); //file does not exist but ofstream will create one
//testing to ensure file is open
if(!outfile.is_open())
{
cout << "File is not open
" ;
}
return 0;
} can you adjust it so i am using the overloaded<< and >> and finish the code for me, quickly please

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

Students also viewed these Databases questions

Question

Do you think physicians should have unions? Why or why not?

Answered: 1 week ago