Question
Code I have so far: Source.cpp : #include #include #include #include using namespace std; #include WitPerson.h void addUser(vector &people, string category); void User() { cout
Code I have so far:
Source.cpp :
#include
#include
#include
#include
using namespace std;
#include "WitPerson.h"
void addUser(vector
void User() { cout
int main() {
vector
vector
//Manual
int user_choice;
int i = 0;
do {
cout
cin >> user_choice;
cin.ignore();
switch (user_choice) {
case 1:
addUser(people, "Student");
break;
case 2:
addUser(people, "Faculty");
break;
case 3:
addUser(people, "Staff");
break;
case 4:
cout
i = 0;
for (auto it = people.begin(); it != people.end(); it++, i++) {
cout
cout
cout
cout
cout
}
break;
default:
cout
for (auto it = people.begin(); it != people.end(); it++, i++) {
cout
cout
cout
cout
cout
}
return 0;
} //switch end
} while (people.size()
cout
i = 0;
for (auto it = people.begin(); it != people.end(); it++, i++) {
cout
cout
cout
cout
cout
}
return 0;
}
void addUser(vector
string user_info;
cout
getline(cin, user_info);
cin.ignore();
//tokenize string
string token;
size_t commaPos;
string name, addr, wnum;
int counter = 1;
user_info += ',';
while (user_info.size() != 0)
{
commaPos = user_info.find(",");
if (commaPos != string::npos)
{
token = user_info.substr(0, commaPos);
user_info = user_info.substr(commaPos + 1);
if (counter == 1)
{
name = token;
counter++;
}//end 1st nested if
else if (counter == 2)
{
addr = token;
counter++;
}//end 2nd nested if
else if (counter == 3)
{
wnum = token;
counter++;
}//end 3rd nested if
} //end whole if statement
else
{
token = user_info;
user_info = "";
}
//WitPerson person = new WitPerson(c1, c2, c3, role);
//people[index] = *p;
} //end while loop
people.push_back(WitPerson(name, addr, wnum, role));
}
WitPerson.cpp :
#include
#include
#include
using namespace std;
#include "WitPerson.h"
//Initialization
WitPerson::WitPerson() {
WitPerson::Name = "Default";
WitPerson::Addr = "Default";
WitPerson::Wnum = "0";
WitPerson::Category = "Unknown";
WitPerson::Role = "Unknown";
}
//Constructor
WitPerson::WitPerson(string name, string addr, string wNum, string role) {
WitPerson::Name = name;
WitPerson::Addr = addr;
WitPerson::Wnum = wNum;
WitPerson::Role = role;
}
//Copy Constructor
WitPerson::WitPerson(const WitPerson &person) {
Name = person.Name;
Addr = person.Addr;
Wnum = person.Wnum;
Category = person.Category;
Role = person.Role;
}
//Destructor
WitPerson::~WitPerson(void) {
//delete this;
}
//stream insertion operator
ostream& operator
strm
strm
strm
strm
return strm;
}
//stream extraction operator
istream& operator >> (istream& in, WitPerson&c)
{
cout
in >> c.Name;
cout
in >> c.Addr;
cout
in >> c.Wnum;
cout
in >> c.Role;
return in;
}
ofstream& operator
{
ofs
return ofs;
}//end ofstream
ifstream& operator >> (ifstream& ifs, WitPerson &src)
{
string record;
while (getline(ifs, record))
{
int index = record.find('/');
src.Name = record.substr();
}
return ifs;
}//end ifstream
//initialize overloaded operator
WitPerson& WitPerson::operator=(const WitPerson &Person) {
if (this != &Person) {
Name = Person.Name;
Addr = Person.Addr;
Wnum = Person.Wnum;
Category = Person.Category;
Role = Person.Role;
}
return *this;
}
WitPerson.h :
#ifndef WITPERSON_H
#define WITPERSON_H
class WitPerson {
friend ostream& operator
friend istream& operator >> (istream&, WitPerson&);
friend ofstream& operator
friend ifstream& operator >> (ifstream&, WitPerson &);
public:
WitPerson();
WitPerson(string name, string addr, string wNum, string role);
WitPerson(const WitPerson &person);
WitPerson& operator=(const WitPerson&);
~WitPerson(void);
string getName(void) const { return Name; };
string getAddr(void) const { return Addr; };
string getWnum(void) const { return Wnum; };
string getCategory(void) const { return Category; };
string getRole(void) const { return Role; };
virtual string payMe(void) = 0; //A pure virtual function
private:
string Name;
string Addr;
string Wnum;
string Category;
string Role;
};
#endif
Next in your project, create 3 new header files to hold: WitFaculty class WitStaff class WitStudent class all of which publicly inherit from WitPerson. You'll want to implement payMe() differently for all 3 classes. You will no longer be able to instantiate an instance of WitPerson directly only the 3 child classes. Remember that you'll also need to declare & implement your constructors, destructor, and assignment operator for each new class. When you run payMe(), you'll print out the name of the person and the gross amount of their paycheck (forget taxes & deductions for now) on the screen You will need to collect additional information for each class in your database. Faculty are paid a salary, so they are paid the same amount (whatever it is) each pay period Staff are usually paid on an hourly basis, so their pay is hours rate up to 40 hours, and they get time and a half for all hours over 40. The rate is steady, but hours may vary each period. Students are hourly and work less than 40 hours. Their rate is generally less than staff. In your main() function, when you are ready to create a new instance, you must create the appropriate child class using the new() operator. You should not need to modify the code that deals with your vector template. Run payMe) for each member in the database
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started