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 inherits from the ProductionWorker class. The TeamLeader class should have fields 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 methods for the class. Demonstrate the class by writing a program that uses a TeamLeader object.

Respuesta :

Answer:

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

class Employee

{

private:

string name; // Employee name

string number; // Employee number

string hireDate; // Hire date

public:

Employee()

{ name = ""; number = ""; hireDate = ""; }

Employee(string aName, string aNumber, string aDate)

{ name = aName; number = aNumber; hireDate = aDate; }

void setName(string n)

{ name = n; }

void setNumber(string num)

{ number = num; }

void setHireDate(string date)

{ hireDate = date; }

string getName() const

{ return name; }

string getNumber() const

{ return number; }

string getHireDate() const

{ return hireDate; }

};

class ProductionWorker : public Employee

{

private:

int shift; // The worker's shift

double payRate; // The worker's hourly pay rate

public:

ProductionWorker() : Employee()

{ shift = 0; payRate = 0.0; }

ProductionWorker(string aName, string aNumber, string aDate,

int aShift, double aPayRate) : Employee(aName, aNumber, aDate)

{ shift = aShift; payRate = aPayRate; }

void setShift(int s)

{ shift = s; }

void setPayRate(double r)

{ payRate = r; }

int getShiftNumber() const

{ return shift; }

string getShiftName() const

{ if (shift == 1)

return "Day";

else if (shift == 2)

return "Night";

else

return "Invalid";

}

double getPayRate() const

{ return payRate; }

};

class TeamLeader : public ProductionWorker

{

private:

double monthlyBonus; // Monthly bonus amount

double requiredTraining; // Required training hours

double completedTraining; // Completed training hours

public:

};

void displayInfo(ProductionWorker);

void displayInfo(TeamLeader);

int main()

{

ProductionWorker pw("John Jones", "123", "1/1/2006", 2, 18.00);

displayInfo(pw);

/* remove the comment to enable

TeamLeader leader("John Jones", "123", "1/1/2006", 2, 18.00,

500.0, 20.0, 12.5);

displayInfo(leader);

*/

return 0;

}

void displayInfo(ProductionWorker e)

{

cout << setprecision(2) << fixed << showpoint;

cout << "Name: "

<< e.getName() << endl;

cout << "Employee number: "

<< e.getNumber() << endl;

cout << "Hire date: "

<< e.getHireDate() << endl;

cout << "Shift: "

<< e.getShiftName() << endl;

cout << "Shift number: "

<< e.getShiftNumber() << endl;

cout << "Pay rate: "

<< e.getPayRate() << endl;

}

void displayInfo(TeamLeader e)

{

/* enable this section to print

cout << setprecision(2) << fixed << showpoint;

cout << "Name: "

<< e.getName() << endl;

cout << "Employee number: "

<< e.getNumber() << endl;

cout << "Hire date: "

<< e.getHireDate() << endl;

cout << "Shift: "

<< e.getShiftName() << endl;

cout << "Shift number: "

<< e.getShiftNumber() << endl;

cout << "Pay rate: "

<< e.getPayRate() << endl;

cout << "Monthly bonus: $"

<< e.getMonthlyBonus() << endl;

cout << setprecision(1);

cout << "Required training hours: "

<< e.getRequiredTraining() << endl;

cout << "Completed training hours: "

<< e.getCompletedTraining() << endl;

*/

}

Hope it helps.