Question: The starter code is included below. Modify the Employee class -Add an exception class for : InvalidHireDate -Add code to the Employee class to check
The starter code is included below. Modify the Employee class -Add an exception class for : InvalidHireDate -Add code to the Employee class to check if the hire date is in the MM/DD/YYYY format.
Modify the Production Worker Class -Add two exception classes: InvalidShift and InvalidPayRate (for if the rate they give isnt a double). -Add two new test functions: TestShift (int shift) TestPayRate (double rate)
Add a static function for creating a new ProductionWorker object. Static ProductionWorker*createNewProductionWorker(); This function should ask the user for the employee name, hire date, shift, hourly pay rate, and then dynamically make a ProductionWorker object from inside a try block. After the try block, there should be catch blocks to handle the three types of exceptions: InvalidHIreDate, InvalidShift, InvalidPayRate.
#include
#include #include #include using namespace std; class Employee { private: string employeeName; int employeeNumber; int hireDate; public: void setemployeeName(string employeeName); void setemployeeNumber(int); void sethireDate(int); string getemployeeName() const; int getemployeeNumber() const; int gethireDate() const; Employee(); }; void Employee::setemployeeName(string employeeName) { employeeName = employeeName; } void Employee::setemployeeNumber(int b) { employeeNumber = b; } void Employee::sethireDate(int d) { hireDate = d; } string Employee::getemployeeName() const { return employeeName; } int Employee::getemployeeNumber() const { return employeeNumber; } int Employee::gethireDate() const { return hireDate; } Employee::Employee() { } class ProductionWorker :public Employee { private: int Shift; double hourlyPay; public: void setShift(int); void sethourlyPay(double); int getShift() const; double gethourlyPay() const; ProductionWorker(); }; void ProductionWorker::setShift(int s) { Shift = s; } void ProductionWorker::sethourlyPay(double p) { hourlyPay = p; } int ProductionWorker::getShift() const { return Shift; } double ProductionWorker::gethourlyPay() const { return hourlyPay; } ProductionWorker::ProductionWorker() { } int main() { ProductionWorker info; string name; int num; int date; int shift; char command; double pay; while (true) { cout << " Supported Commands "; cout << "C Create a new ProductionWorker object "; cout << "H Print help text "; cout << "P Print production worker information "; cout << "Q Quit (end the program) "; cout << "Enter Command:"; cin >> command; if (command == 'C') { cout << "Please enter employee name: "; cin >> name; cout << "Please enter employee number: "; cin >> num; cout << "Please enter employee hire date using the format "; cout << "2 digit month, 2 digit day, 4 digit year as one number: "; cout << "(Example August 12 1981 = 08121981)"; cin >> date; cout << "Which shift does the employee work: "; cout << "Enter 1, 2, or 3"; cin >> shift; cout << "Please enter the employee's rate of pay: "; cin >> pay; info.setemployeeName(name); info.setemployeeNumber(num); info.sethireDate(date); info.setShift(shift); info.sethourlyPay(pay); system("pause"); } if (command == 'H') { cout << " Supported Commands "; cout << "C Create a new ProductionWorker object "; cout << "H Print help text "; cout << "P Print production worker information "; cout << "Q Quit (end the program) "; } if (command == 'P'){ cout << " This is the info on the employee you just made: "; cout << "Name: " << info.getemployeeName() << endl; cout << "Number: " << info.getemployeeNumber() << endl; cout << "Hire Date: " << info.gethireDate() << endl; cout << "Shift: " << info.getShift() << endl; cout << setprecision(2) << fixed; cout << "Pay Rate: " << info.gethourlyPay() << endl; } if (command == 'Q'){ system("exit"); } }}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
