Part 1: Employee and ProductionWorker classes Design a class named Employee. The
ID: 3633406 • Letter: P
Question
Part 1: Employee and ProductionWorker classesDesign a class named Employee. The class should keep the following information in member variables:
Employee Name
Employee Number
Hire 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. Write one or more constructors and the appropriate accessor and mutator functions for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object.
Part 2: 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 Employee class you created in part 1. The ShiftSupervisor class 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. Demonstrate the class by writing a program that uses a ShiftSupervisor object.
Part 3: 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 part 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. Demonstrate the class by writing a program that uses a TeamLeader object.
NOTE: You can use the same driver program to test all parts of this program implementation. You do not need to create a separate driver program for each step.
Explanation / Answer
Dear,
1)
//Header file section
#include< iostream >
#include< string >
using namespace std;
//defining class Employee
class Employee
{
private:string EmpName;
int EmpNumber;
string Hiredate;
//Default constructor
public: Employee()
{
EmpName=" ";
EmpNumber=0;
Hiredate=" ";
}
//Parameterized constructor
Employee(string name,int number,string date)
{
EmpName=name;
EmpNumber=number;
Hiredate=date;
}
//Member functions
void setEmpName(string);
void setEmpNumber(int);
void setHireDate(string);
string getEmpName();
int getEmpNumber();
string getHireDate();
};
//Defining member functions
void Employee::setEmpName(string str)
{
EmpName=str;
}//end setEmpName
void Employee::setEmpNumber(int num)
{
EmpNumber=num;
}//end setEmpNumber
void Employee::setHireDate(string date)
{
Hiredate=date;
}//end setHireDate
string Employee::getEmpName()
{
return EmpName;
}//end getEmpName
int Employee::getEmpNumber()
{
return EmpNumber;
}//end getEmpNumber
string Employee::getHireDate()
{
return Hiredate;
}//end getHireDate
//defining derived class ProductionWorker
class ProductionWorker:public Employee
{
private:int Shift;
double HourlyPay;
//Default constructor
public: ProductionWorker()
{
Shift=0;
HourlyPay=0;
}
//Parameterized constructor
ProductionWorker(int sh,double pay)
{
Shift=sh;
HourlyPay=pay;
}
void setShift(int);
void setHourlyPay(double);
int getShift();
double getHourlyPay();
};
//Defining member functions
void ProductionWorker::setShift(int sh)
{
Shift=sh;
}//end setShift
void ProductionWorker::setHourlyPay(double pay)
{
HourlyPay=pay;
}//end setHourlyPay
int ProductionWorker::getShift()
{
return Shift;
}//end getShift
double ProductionWorker::getHourlyPay()
{
return HourlyPay;
}//end getHourlyPay
//Main function
int main()
{//Start main
int shift;
double pay;
//Inputting data
cout<<" 1-DayShift 2-Night"<<endl;
cout<<"Enter shift:";
cin>>shift;
cout<<"Enter hourly pay:";
cin>>pay;
//creating ProductionWorker object
ProductionWorker emp1(shift,pay);
//setting the values to employee class using
//emp1 object
emp1.setEmpName("Winston");
emp1.setEmpNumber(562);
emp1.setHireDate(" June:11");
//outputting data using accessor functions
cout<<"Employee Details:"<<endl<<endl;
cout<<"Employee Name:"<<emp1.getEmpName()<<endl;
cout<<"Employee Number:"<<emp1.getEmpNumber()<<endl;
cout<<"Employee Hire Date:"<<emp1.getHireDate()<<endl;
cout<<"Employee Shift:"<<emp1.getShift()<<endl;
cout<<"EmployeeHourlyPay:"<<emp1.getHourlyPay()<<endl;
//Pause system for a while
system("pause");
return 0;
}
//end main
2)
#include< iostream >
#include< string >
using namespace std;
//defining class Employee
class Employee
{
protected:string EmpName;
int EmpNumber;
string Hiredate;
//Default constructor
public: Employee()
{
EmpName=" ";
EmpNumber=0;
Hiredate=" ";
}
//Parameterized constructor
Employee(string name,int number,string date)
{
EmpName=name;
EmpNumber=number;
Hiredate=date;
}
//Member functions
public: void setEmpName(string);
void setEmpNumber(int);
void setHireDate(string);
string getEmpName();
int getEmpNumber();
string getHireDate();
};
//Defining member functions
void Employee::setEmpName(string str)
{
EmpName=str;
}//end setEmpName
void Employee::setEmpNumber(int num)
{
EmpNumber=num;
}//end setEmpNumber
void Employee::setHireDate(string date)
{
Hiredate=date;
}//end setHireDate
string Employee::getEmpName()
{
return EmpName;
}//end getEmpName
int Employee::getEmpNumber()
{
return EmpNumber;
}//end getEmpNumber
string Employee::getHireDate()
{
return Hiredate;
}//end getHireDate
class ShiftSupervisor: public Employee
{
private: double AnnualSalary;
double AnnualBonus;
public: //Default constructor
ShiftSupervisor()
{
AnnualSalary=0.0;
AnnualBonus=0.0;
}
//parameterized constructor
ShiftSupervisor(double sal, double bonus)
{
AnnualSalary=sal;
AnnualBonus=bonus;
}
//Declaring member functions
public:void setAnnualSalary(double);
void setAnnualBonus(double);
double getAnnualSalary();
double getAnnualBonus();
};
void ShiftSupervisor::setAnnualBonus(double bonus)
{
AnnualBonus=bonus;
}//end setAnnualBonus
void ShiftSupervisor::setAnnualSalary(double sal)
{
AnnualSalary=sal;
}//end setAnnualSalary
double ShiftSupervisor::getAnnualBonus()
{
return AnnualBonus;
}//end getAnnualBonus
double ShiftSupervisor::getAnnualSalary()
{
return AnnualSalary;
}//end getAnnualSalary
//Main function
void main()
{
//start main
//object to class ShiftSupervisor
ShiftSupervisor emp1;
//variable declaration
string name;
string date;
double Abonus,Asalary;
//Set data values to class object
cout<<"Enter Employee Name:";
cin>>name;
emp1.setEmpName(name);
emp1.setEmpNumber(562);
emp1.setHireDate("June 21");
cout<<"Enter Anual Bonus:";
cin>>Abonus;
emp1.setAnnualBonus(Abonus);
cout<<"Enter Anual Salary:";
cin>>Asalary;
emp1.setAnnualSalary(Asalary);
//Outputting data by calling Accessor functions
cout<<"----Shift Supervisor Details---"<<endl;
cout<<"Employee Name:"<<emp1.getEmpName()<<endl;
cout<<"Employee Number:"<<emp1.getEmpNumber()<<endl;
cout<<"Employee Hir Date:"<<emp1.getHireDate()<<endl;
cout<<"Employee Annual salary:"<<emp1.getAnnualSalary()<<endl;
cout<<"Employee Annual Bonus :"<<emp1.getAnnualBonus()<<endl;
system("pause");
}//end main
3)
//Header file section
#include< iostream >
#include< string >
using namespace std;
//defining class Employee
class Employee
{
private:string EmpName;
int EmpNumber;
string Hiredate;
//Default constructor
public: Employee()
{
EmpName=" ";
EmpNumber=0;
Hiredate=" ";
}
//Parameterized constructor
Employee(string name,int number,string date)
{
EmpName=name;
EmpNumber=number;
Hiredate=date;
}
//Member functions
void setEmpName(string);
void setEmpNumber(int);
void setHireDate(string);
string getEmpName();
int getEmpNumber();
string getHireDate();
};
//Defining member functions
void Employee::setEmpName(string str)
{
EmpName=str;
}//end setEmpName
void Employee::setEmpNumber(int num)
{
EmpNumber=num;
}//end setEmpNumber
void Employee::setHireDate(string date)
{
Hiredate=date;
}//end setHireDate
string Employee::getEmpName()
{
return EmpName;
}//end getEmpName
int Employee::getEmpNumber()
{
return EmpNumber;
}//end getEmpNumber
string Employee::getHireDate()
{
return Hiredate;
}//end getHireDate
//defining derived class ProductionWorker
class ProductionWorker:public Employee
{
private:int Shift;
double HourlyPay;
//Default constructor
public: ProductionWorker()
{
Shift=0;
HourlyPay=0;
}
//Parameterized constructor
ProductionWorker(int sh,double pay)
{
Shift=sh;
HourlyPay=pay;
}
void setShift(int);
void setHourlyPay(double);
int getShift();
double getHourlyPay();
};
//Defining member functions
void ProductionWorker::setShift(int sh)
{
Shift=sh;
}//end setShift
void ProductionWorker::setHourlyPay(double pay)
{
HourlyPay=pay;
}//end setHourlyPay
int ProductionWorker::getShift()
{
return Shift;
}//end getShift
double ProductionWorker::getHourlyPay()
{
return HourlyPay;
}//end getHourlyPay
class TeamLeader:public ProductionWorker
{
private: double MonthlyBonus;
//variable to hold number of training hours required
int TRequiredHours;
//variable to hold number of training hours attended
int TAttendHours;
public: //Default constructors
TeamLeader()
{
MonthlyBonus=0.0;
TRequiredHours=0;
TAttendHours=0;
}
//Parameterized constructors
TeamLeader(double MBonus,int TRhours,int TAhours)
{
MonthlyBonus=MBonus;
TRequiredHours=TRhours;
TAttendHours=TAhours;
}
void setMonthlyBonus(double);
void setTRequiredHours(int);
void setTAttendHours(int);
double getMonthlyBonus();
int getTRequiredHours();
int getTAttendHours();
};
//Function definitions
void TeamLeader::setMonthlyBonus(double MBonus)
{
MonthlyBonus=MBonus;
}
//end setMonthlyBonus
void TeamLeader::setTAttendHours(int Ahours)
{
TAttendHours=Ahours;
}//end setTAttendHours
void TeamLeader::setTRequiredHours(int Rhours)
{
TRequiredHours=Rhours;
}//end setTRequiredHours
double TeamLeader::getMonthlyBonus()
{
return MonthlyBonus;
}//end getMonthlyBonus
int TeamLeader::getTAttendHours()
{
return TAttendHours;
}//end getTAttendHours
int TeamLeader::getTRequiredHours()
{
return TRequiredHours;
}//end getTRequiredHours
void main()
{
TeamLeader lead1;
int shift;
double pay;
int requiredHours,attendHours,Mbonus;
//Inputting data
lead1.setEmpName("Winston");
lead1.setEmpNumber(562);
lead1.setHireDate(" June:11");
cout<<" 1-DayShift 2-Night"<<endl;
cout<<"Enter shift:";
cin>>shift;
cout<<"Enter hourly pay:";
cin>>pay;
lead1.setShift(shift);
lead1.setHourlyPay(pay);
cout<<"Enter Montly Bonus:";
cin>>Mbonus;
cout<<"Enter Required Hours:";
cin>>requiredHours;
lead1.setTRequiredHours(requiredHours);
cout<<"Enter Attended hours:";
cin>>attendHours;
lead1.setTAttendHours(attendHours);
//Outputting Data
cout<<"-----Team Lead Details-----"<<endl;
cout<<"Name:"<<lead1.getEmpName()<<endl;
cout<<"EmpNumber:"<<lead1.getEmpNumber()<<endl;
cout<<"HireDate:"<<lead1.getHireDate()<<endl;
cout<<"Shift:"<<lead1.getShift()<<endl;
cout<<"Hourly Pay:"<<lead1.getHourlyPay()<<endl;
cout<<"Monthly Bonus:"<<lead1.getMonthlyBonus()<<endl;
cout<<"Required TrainingHours:"
<<lead1.getTRequiredHours()<<endl;
cout<<"Attended Training Hours:"
<<lead1.getTAttendHours()<<endl;
//To pause system for a while
system("pause");
}