C++ assignment question 1. Employee and ProductionWorker ClassesDesign a class n
ID: 673349 • Letter: C
Question
C++ assignment question
1. Employee and ProductionWorker ClassesDesign a class named Employee.
The class should keep the following information in
Employee name
Employee number
Hire date (A class called 'date')
Write one or more constructors and the appropriate accessor and mutator functions for the class. Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:
Shift (an integer)
Hourly pay rate (a double)
The workday is divided into two shifts: day and night. The shift variable will hold an integer value representing the shift that the employee works. The day shift is shift 1, and the night shift is shift 2. Make the shift an enumerated type. Write one or more constructors and the appropriate accessor and mutator functions for the class.
There should be a Pay function for all employees - pure virtual. For Productio worker, they should be paid their hourly rate plus 1/2 additional if they work the night shift. This combination should be returned from the pay function.
2. ShiftSupervisor Class
ShiftSupervisor Class In a particular factory a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Design a ShiftSupervisor class that is derived from the Employeeclass you created in Programming Challenge 1. The ShiftSupervisorclass should have a member variable that holds the annual salary and a member variable that holds the annual production bonus that a shift supervisor has earned. Write one or more constructors and the appropriate accessor and mutator functions for the class.
The Pay function for Shift Supervisor should return a combination of their normal pay and any bonus pay they earn.
3. TeamLeader Class
TeamLeader Class In a particular factory, a team leader is an hourly paid production worker who leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that extends the ProductionWorker class you designed in Programming Challenge 1. The TeamLeader class should have member variables for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Write one or more constructors and the appropriate accessor and mutator functions for the class.
The Pay function for TeamLeader should show return a combination of their hourly pay and any montly bonus pay they earn based on education they have received.
Main Function
Create a main program that uses the four classes described in #1 - #3 above. The main function should have the following menu:
Create a Production Worker
Create a Shift Supervisor
Crate a Team Leader
Pay Everyone
Exit the Program
Create an array of employee pointers that will receive the instantiation of dynamically allocated Production Workers, Shift Supervisors and Team Leaders. You can do these one at a time (when the user select #1 for example, prompt them for the needs of a Production Worker so they get paid appropriately, for example. Or, ask the user how many Production Workers they want to input, and accomodate that action as well).
Also, you should prompt the user for a common identifying quality for each employee that is inherited out of the Employee class. For example: Employee ID, First and last names would be nice. This will also show that you understand the usage of inherited attributes from the parent class.
Make sure that each of these derived objects uses the specifics of each employee type to make sure they get paid appropriately. For example:
Team Leader gets additional pay (monthly) if they have had education hours to a certain point for the pay period. You should ask the user for the total hours of education they earned for that pay period and then show the total pay they receive including the bonus based on if they met the requirements for minimum education for that period.
Production Worker gets paid more on the night shift (2), so ask the user if the emploee worked the night or day shift for the period (not a combination), and set this information into the object itself (using a mutator for shift). Then, when their pay function is executed, it will take into account their shift in outputing their total pay.
Shift Supervisor gets a bonus if their team met their production goals. So here, ask if their team met their production goals, and set this into the object using a mutator fuction that sets a flag. Then, when their pay function is executed, it will check this flag and then add to their total pay period their yearly bonus/total periods per year. If you want to vary this, you can also ask if the superviror is being paid weekly (52/year), monly (12/year) or semi-monthly (26/year). Or, you can just assume monthly.
Note: Classes should NEVER do cout's or cin's inside the class unless the class is a derived class of cout/cin, or, if the cout is one to display a critical error. Do all of your data input inside the main() function which instantitates the classes.
Menu item #4 should go through all of the pointers in the array (Employee *employeeArray[xx]) and execute their pay function formatting the ouptut into a relatively nice report. See an example using the attached example programs.
Explanation / Answer
1.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
private:
char EmpName;
int EmpNum;
int HireDate;
public:
void setEmpName(char);
void setEmpNum(int);
void setHireDate(int);
char getEmpName() const;
int getEmpNum() const;
int getHireDate() const;
Employee();
};
void Employee::setEmpName(char x)
{
EmpName = x;
}
void Employee::setEmpNum(int y)
{
EmpNum = y;
}
void Employee::setHireDate(int z)
{
HireDate = z;
}
char Employee::getEmpName() const
{
return EmpName;
}
int Employee::getEmpNum() const
{
return EmpNum;
}
int Employee::getHireDate() const
{
return HireDate;
}
Employee::Employee()
{
cout << "I will ask you some questions about an employee. ";
}
class ProductionWorker : public Employee
{
private:
int Shift;
double HourlyPayRate;
public:
void setShift(int);
void setHourlyPayRate(double);
int getShift() const;
double getHourlyPayRate() const;
ProductionWorker();
};
void ProductionWorker::setShift(int a)
{
Shift = a;
}
void ProductionWorker::setHourlyPayRate(double b)
{
HourlyPayRate = b;
}
int ProductionWorker::getShift() const
{
return Shift;
}
double ProductionWorker::getHourlyPayRate() const
{
return HourlyPayRate;
}
ProductionWorker::ProductionWorker()
{
cout << "After answering the questions, ";
cout << "I will display the employee's information. ";
}
int main()
{
ProductionWorker info;
char name[100];
int num;
int date;
int shift;
double rate;
cout << "What is the employee's name? ";
cin.getline(name, 100);
cout << "What is the employee's number? ";
cin >> num;
cout << "What is the employee's hire date? ";
cout << "(Month, day, and year without any slashes, ";
cout << "dashes, commas, or other punctuation.) ";
cout << "For example, January 14, 1983 would look like 01141983. ";
cin >> date;
cout << "Does the employee work shift 1 or shift 2? ";
cin >> shift;
cout << "How much does the employee make per hour? ";
cin >> rate;
info.setEmpName(name[100]);
info.setEmpNum(num);
info.setHireDate(date);
info.setShift(shift);
info.setHourlyPayRate(rate);
cout << " Here is the employee's data: ";
cout << "Employee's Name: " << info.getEmpName() << endl;
cout << "Employee's Number: " << info.getEmpNum() << endl;
cout << "Employee's Hire Date: " << info.getHireDate() << endl;
cout << "Employee's Shift: " << info.getShift() << endl;
cout << setprecision(2) << fixed;
cout << "Employee's Hourly Pay Rate: $" << info.getHourlyPayRate() << endl << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.