12.7k views
4 votes
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.

2 Answers

2 votes

Final answer:

To design a TeamLeader class that inherits from the ProductionWorker class, the TeamLeader class should have fields for monthly bonus, required training hours, and attended training hours. This can be achieved by creating a TeamLeader class that extends the ProductionWorker class and includes the necessary fields and methods. The class can then be demonstrated by creating a TeamLeader object and using its methods to access and modify the attributes.

Step-by-step explanation:

TeamLeader Class



The TeamLeader class should inherit from the ProductionWorker class and include fields for the monthly bonus amount, required number of training hours, and number of training hours attended.



Here is an example of how the TeamLeader class could be implemented:



class TeamLeader extends ProductionWorker {
private double monthlyBonus;
private int requiredTrainingHours;
private int attendedTrainingHours;

public TeamLeader(String name, String employeeNumber, int shift, double hourlyPay, double monthlyBonus, int requiredTrainingHours, int attendedTrainingHours) {
super(name, employeeNumber, shift, hourlyPay);
this.monthlyBonus = monthlyBonus;
this.requiredTrainingHours = requiredTrainingHours;
this.attendedTrainingHours = attendedTrainingHours;
}

public double getMonthlyBonus() {
return monthlyBonus;
}

public int getRequiredTrainingHours() {
return requiredTrainingHours;
}

public int getAttendedTrainingHours() {
return attendedTrainingHours;
}

public void setMonthlyBonus(double monthlyBonus) {
this.monthlyBonus = monthlyBonus;
}

public void setRequiredTrainingHours(int requiredTrainingHours) {
this.requiredTrainingHours = requiredTrainingHours;
}

public void setAttendedTrainingHours(int attendedTrainingHours) {
this.attendedTrainingHours = attendedTrainingHours;
}
}



To demonstrate the TeamLeader class, you can create a TeamLeader object and use its methods to access and modify the attributes:



TeamLeader teamLeader = new TeamLeader("John Doe", "123456", 1, 20.0, 500.0, 40, 30);

double bonus = teamLeader.getMonthlyBonus();
int requiredHours = teamLeader.getRequiredTrainingHours();
int attendedHours = teamLeader.getAttendedTrainingHours();

teamLeader.setMonthlyBonus(600.0);
teamLeader.setRequiredTrainingHours(50);
teamLeader.setAttendedTrainingHours(35);

User Smarty
by
7.3k points
1 vote

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.

User Hyztname
by
6.8k points