Question

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. Demonstrate the class by writing a program that uses a TeamLeader object.

Solution

Verified

Step 1

1 of 5
//contents of Employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string>
using namespace std;

class Employee{
private:
string name;
int number;
int hireDay;
int hireMonth;
int hireYear;
public:
//default constructor
Employee(){
//message added for demonstration purposes
cout << "Default constructor of Employee class";
cout << " now running...\n";

//by default assign empty string to name
//and 0 to other members
name = "";
number = 0;
hireDay = 0;
hireMonth = 0;
hireYear = 0;
}

//overloaded constructor
Employee(string n, int num, int d, int m, int y){
//message added for demonstration purposes
cout << "Overloaded constructor of Employee class";
cout << " now running...\n";

name = n;
number = num;
//check for invalid input for day, month and year
if(d < 0 || d > 31 || m < 0 ||
m > 12 || y < 1900 || y > 2018){
//print error message then exit
cout << "Error! Invalid hire date! Now terminating!\n";
exit(EXIT_FAILURE);
}
else{
//otherwise set hire date
hireDay = d;
hireMonth = m;
hireYear = y;
}
}

//getter functions
string getName() const{
return name;
}

int getNumber() const{
return number;
}

string getHireDate() const{
//create empty string
string dt = "";

//fill string with data
dt += to_string(hireDay) + "/" +
to_string(hireMonth) + "/" +
to_string(hireYear);

//return string
return dt;
}

//setter functions
void setName(string n){
name = n;
}

void setNumber(int num){
number = num;
}

void setHireDate(int d, int m, int y){
//check for invalid input for day, month and year
if(d < 0 || d > 31 || m < 0 ||
m > 12 || y < 1900 || y > 2018){
//print error message then exit
cout << "Error! Invalid hire date! Now terminating!\n";
exit(EXIT_FAILURE);
}
else{
//otherwise set hire date
hireDay = d;
hireMonth = m;
hireYear = y;
}
}


};

#endif

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionDavid A. Patterson, John L. Hennessy
220 solutions
Starting Out with C++ from Control Structures to Objects 8th Edition by Godfrey Muganda, Judy Walters, Tony Gaddis

Starting Out with C++ from Control Structures to Objects

8th EditionGodfrey Muganda, Judy Walters, Tony Gaddis
1,294 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionRamez Elmasri, Shamkant B. Navathe
687 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions

Related questions