C++ assignment question 1. Employee and ProductionWorker ClassesDesign a class n
ID: 3667004 • 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.
Explanation / Answer
given below are the code :
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Employee
{
private:
string EmpNm;
int Empid;
int HireDate;
public:
void setEmpNm(string);
void setEmpid(int);
void setHireDate(int);
string getEmpNm() const;
int getEmpid() const;
int getHireDate() const;
Employee();
};
void Employee::setEmpNm(string x)
{
EmpNm = x;
}
void Employee::setEmpid(int y)
{
Empid = y;
}
void Employee::setHireDate(int z)
{
HireDate = z;
}
string Employee::getEmpNm() const
{
return EmpNm;
}
int Employee::getEmpid() const
{
return Empid;
}
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 PayRatehr;
public:
void setShift(int);
void setPayRatehr(double);
int getShift() const;
double getPayRatehr() const;
ProductionWorker();
};
void ProductionWorker::setShift(int a)
{
Shift = a;
}
void ProductionWorker::setPayRatehr(double b)
{
PayRatehr = b;
}
int ProductionWorker::getShift() const
{
return Shift;
}
double ProductionWorker::getPayRatehr() const
{
return PayRatehr;
}
ProductionWorker::ProductionWorker()
{
}
class ShiftSupervisor : public Employee
{
private:
double asalary;
double pbonus;
public:
void setasalary(double);
void setpbonus (double);
double getasalary() const;
double getpbonus() const;
ShiftSupervisor ();
};
void ShiftSupervisor:: setasalary(double m )
{
asalary = m;
}
void ShiftSupervisor:: setpbonus(double n)
{
pbonus = n;
}
double ShiftSupervisor:: getasalary() const
{
return asalary;
}
double ShiftSupervisor:: getpbonus() const
{
return pbonus;
}
ShiftSupervisor:: ShiftSupervisor()
{
}
int main()
{
ProductionWorker info;
string name;
int num;
int date;
int shift;
double rate;
ShiftSupervisor inf;
double sal;
double bonus;
cout << "enter the employee's name= ";
cin >> name;
cout << "enter the employee's id= ";
cin >> num;
cout << "enter the employee's hire date ";
cout << "(Month, day, and year without any slashes,dashes, commas, or other punctuation.) ";
cout << "like, January 26, 2003 would look like 01262003. ";
cin >> date;
cout << "the employee work shift 1 or shift 2= ";
cin >> shift;
cout << "the employee make per hour rate= ";
cin >> rate;
cout << "employee annual salary= ";
cin >>sal;
cout << "employee production bonus= ";
cin >>bonus;
info.setEmpNm(name);
info.setEmpid(num);
info.setHireDate(date);
info.setShift(shift);
info.setPayRatehr(rate);
inf.setasalary(sal );
inf.setpbonus (bonus);
cout << " Here is the employee's data: ";
cout << "Employee's Name: " << info.getEmpNm() << endl;
cout << "Employee's Number: " << info.getEmpid() << endl;
cout << "Employee's Hire Date: " << info.getHireDate() << endl;
cout << "Employee's Shift: " << info.getShift() << endl;
cout << "Employee's Hourly Pay Rate: $" << info.getPayRatehr() << endl; cout << "Employee's annual salary: $" << inf.getasalary() << endl;
cout << "Employee's production bonus: $" << inf.getpbonus() << 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.