project6-testA.tab Your program should match the following output exactly: (user
ID: 3828334 • Letter: P
Question
project6-testA.tab
Your program should match the following output exactly: (user input in bold text)
Create the following
Objectives 1. Practice using inheritance 2. Practice using polymorphism 3. Practice using an STL container Assignment For this project, you will write a complete C++ program in CodeLite (create a new project using the 2170 template) to handle a staff directory and payroll. Extend the driver code located in project6-main.cpp. You need to declare an STL container named employees in the processInputs function. Additionally, you need to write the Employee, Cashier and Manager classes. Also, you need to use inheritance and polymorphism appropriately. The Employee class needs to store the employee's name. Employees are paid minimum wage ($7.25) for 40 hours each week. The cashier class needs to store the cashier name and their hourly wage. Cashiers are paid this hourly wage for 40 hours each week. The Manager class needs to store the manager's name, their ID and their weekly salary. Additionally, add a comment identifying the polymorphic method ca in project6-main.cpp. You can use the following input files for this project project6-testA tab project 6-testB tabExplanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h> // for exit()
#include <iomanip> // fixed, setprecision()
#include "Employee.h"
#include "Cashier.h"
#include "Manager.h"
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::getline;
using std::ifstream;
using std::fixed;
using std::setprecision;
bool DEBUG = false; // toggles extra printing
const string DEFAULT_INPUT_FILENAME = "project6-testA.tab";
// Action characters in the input file
const char ADD_EMPLOYEE = 'E';
const char ADD_CASHIER = 'C';
const char ADD_MANAGER = 'M';
const char REMOVE = 'R';
const char PAYROLL = 'P';
const char FIND = 'F';
const char DISPLAY_ALL = 'D';
class Person{
protected:
string name;
double wage;
public:
map<string,Person> m;
virtual void add(Person p)
{
m.add(pair<string,Person>(p.name,p));
}
}
class Employee :: public Person{
public:
EmpLoyee(string n,double w=7.25):name(n),wage(w)
{
}
virtual void add(Employee e)
{
m.add(pair<string,Person>(e.name,e));
}
};
class Cashier :: public Person{
public:
Cashier(string n,double w=10.5):name(n),wage(w)
{
}
virtual void add(Cashier c)
{
m.add(pair<string,Person>(c.name,c));
}
};
class Manager :: public PerSson{
private:
int ID;
public:
Manager(int ID,string n,double w=19):name(n),wage(w)
{
}
virtual void add(Manager m)
{
m.add(pair<string,Person>(m.name,m));
}
};
// Process the inputs in inputFilename
void processInputs( string inputFilename ){
// declare an STL container named employees here
// open file
ifstream fileStream;
fileStream.open( inputFilename.c_str() );
// verify the file is opened correctly
if( ! fileStream ){
cerr << "ERROR: Can not open input file " << inputFilename << "!" << endl;
exit(1);
}
cout << "Importing instructions from " << inputFilename << " ..." << endl;
char action = '';
// while there's more patients to process
// read in the action and make sure that we're not at the end of the file
while( fileStream >> action ){
if( DEBUG ){ cout << "action: " << action << endl; }
string name;
switch( action ){
case ADD_EMPLOYEE:
// get the employee's name from the file
fileStream >> name;
cout << "Adding employee " << name << endl;
Person p = new Employee(name);
p.add(p);
cout << endl;
if( DEBUG ){ displayAll( employees); }
break;
case ADD_CASHIER:
// get the employee's name from the file
fileStream >> name;
float hourlyWage;
fileStream >> hourlyWage;
cout << "Adding cashier " << name << endl;
Person p = new Cahier(name,hourlyWage);
p.add(p);
cout << endl;
if( DEBUG ){ displayAll( employees); }
break;
case ADD_MANAGER:
// get the employee's name from the file
fileStream >> name;
int id;
fileStream >> id;
float salary;
fileStream >> salary;
cout << "Adding manager " << name << endl;
Person p = new Person(name,id,salary);
p.add(p);
cout << endl;
if( DEBUG ){ displayAll( employees); }
break;
case REMOVE:
// get the employee's name from the file
fileStream >> name;
cout << "Removing " << name << endl;
map<string,Person>::iterator it;
it = m.find(name);
if(it == m.end())
{
cout << "Unable to remove " << name << endl;
}
break;
case PAYROLL:
payroll( employees );
break;
case FIND:
// get the employee's name from the file
fileStream >> name;
cout << "Finding " << name << endl;
map<string,Person>::iterator it;
it = m.find(name);
if(it == m.end())
{
cout << "Unable to find " << name << endl;
}
else
cout << it->first;
break;
case DISPLAY_ALL:
displayAll( employees );
break;
default:
cerr << "ERROR: Unknown action " << action << "!" << endl;
exit(1);
}
}
// close the file
fileStream.close();
}
int main( /*int argc, char* argv[] */){
// If just a return (' ') is entered, then use DEFAULT_INPUT_FILENAME.
// Otherwise, read in the input filename from STDIN.
string inputFilename;
cout << "Please enter the input filename (or simply press return to use " << DEFAULT_INPUT_FILENAME << ") ";
getline( cin, inputFilename);
if( inputFilename == ""){
inputFilename = DEFAULT_INPUT_FILENAME;
}
// process transactions in the file
processInputs( inputFilename );
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.