Question: Practice using inheritance Practice using polymorphism Practice using an STL container Program should be in C++ I have written the .h file code with the
Practice using inheritance
Practice using polymorphism
Practice using an STL container
Program should be in C++
I have written the .h file code with the help of Chegg, but in my project, its mentioned that I required .cpp file for every .h file. These are the files I required project6-main.cpp Employee.h Employee.cpp Cashier.h Cashier.cpp Manager.h Manager.cpp rubric6.tx. Ignore the files with bold, I am missing .cpp for every header file. While compiling I am getting many errors also, we are not required to mess with project6-main.cpp this file as it is a driver code and given by professor and we are not required to change anything. Can anyone look at my code and fix those error. I have also added input file to check the output. If more information required please let me know. Other details are motioned below.
For this project, you will write a complete C++ program 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 call in project6-main.cpp. You can use the following input files for this project:
DRIVER CODE // project6-main.cpp
#include #include #include #include // for exit() #include // 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'; // 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 = '\0'; // 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; 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; 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; cout << endl; if( DEBUG ){ displayAll( employees); } break; case REMOVE: // get the employee's name from the file fileStream >> name; cout << "Removing " << name << endl; break; case PAYROLL: payroll( employees ); break; case FIND: // get the employee's name from the file fileStream >> name; cout << "Finding " << name << endl; 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; } My Work
File: Employee.h
#ifndef Included_Employee_H #define Included_Employee_H
#include using namespace std;
class Employee { private: static const float NUM_WORK_HOURS = 40.0; static const float MIN_WAGE_PER_HOUR = 7.25; // $7.25
protected: string name; float wagePerHour; public: Employee(string aName) : name(aName), wagePerHour(MIN_WAGE_PER_HOUR) { }
Employee(string aName, float aWagePerHour) : name(aName) { if (aWagePerHour < MIN_WAGE_PER_HOUR) { aWagePerHour = MIN_WAGE_PER_HOUR; } wagePerHour = aWagePerHour; }
string getName() { return name; }
virtual void display() { cout << name << endl; }
virtual void payroll() { cout << name << " $" << fixed << setprecision(2) << (wagePerHour * NUM_WORK_HOURS) << endl; } };
#endif // Included_Employee_H
File: Cashier.h
#ifndef Included_Cashier_H #define Included_Cashier_H
#include
#include "Employee.h"
using namespace std;
class Cashier : public Employee { public: Cashier(string aName, float aWagePerHour) : Employee(aName, aWagePerHour) { }
virtual void display() { cout << name << " (Cashier hourly wage: $" << fixed << setprecision(2) << wagePerHour << ")" << endl; } };
#endif // Included_Cashier_H
File: Manager.h
#ifndef Included_Manager_H #define Included_Manager_H
#include
#include "Employee.h"
using namespace std;
class Manager : public Employee { private: int managerId; float wagePerWeek;
public: Manager(string aName, int aManagerId, float aWagePerWeek) : Employee(aName), managerId(aManagerId) { wagePerWeek = aWagePerWeek; }
virtual void display() { cout << name << " (Manager id: " << managerId << ", weekly wage: $" << fixed << setprecision(2) << wagePerWeek << ")" << endl; }
virtual void payroll() { cout << name << " $" << fixed << setprecision(2) << wagePerWeek << endl; } };
#endif // Included_Manager_H
INPUT (There re two input files)
D P F Sophia R Sophia E Sophia D P F Sophia R Sophia D F Sophia R Sophia C Jackson 77.91 M Emma 123456789 1234.56 E Aiden C Olivia 42.87 M Lucas 987654321 7890.12 P D R Jackson R Emma R Aiden R Olivia R Lucas D
input file 2:
other input file is large so i am attaching link to access that file (in Link assignment detail is also present)
https://drive.google.com/open?id=0B8OHmjK8INMndVV3QlBWdk5KeFE
OUTPUT
Please enter the input filename (or simply press return to use project6-testA.tab) Importing instructions from project6-testA.tab ... Displaying 0 employees: Weekly payroll: Finding Sophia Unable to find Sophia Removing Sophia Unable to remove Sophia Adding employee Sophia Displaying 1 employee: Sophia Weekly payroll: Sophia $290.00 Finding Sophia Sophia Removing Sophia Displaying 0 employees: Finding Sophia Unable to find Sophia Removing Sophia Unable to remove Sophia Adding cashier Jackson Adding manager Emma Adding employee Aiden Adding cashier Olivia Adding manager Lucas Weekly payroll: Jackson $3116.40 Emma $1234.56 Aiden $290.00 Olivia $1714.80 Lucas $7890.12 Displaying 5 employees: Jackson (Cashier hourly wage: $77.91) Emma (Manager id: 123456789, weekly wage: $1234.56) Aiden Olivia (Cashier hourly wage: $42.87) Lucas (Manager id: 987654321, weekly wage: $7890.12) Removing Jackson Removing Emma Removing Aiden Removing Olivia Removing Lucas Displaying 0 employees:
RUBRIC:
Points Item ---------- -------------------------------------------------------------- _____ / 10 Documentation: Header comment block at the beginning of each file with: + Your full name + Date(s) code was written + Description Comments explaining the role of each variable and major section of code Program solves the assigned problem using methods described in program description: _____ / 15 + Uses an STL container correctly _____ / 15 + Inheritance _____ / 15 + Polymorphism (including a comment identifying the polymorphic call) _____ / 23 Output _____ / 0 Program compiles without errors _____ / 0 Program executes without crashing
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
