1. Add or modify the following operations to the classes named:
void setName(string theName); // change the name of the employee void setPayRate(float thePayRate); // change the hourly or salary pay rates float pay(float hoursWorked) const; // calculate the total income void print() const // print the employee information including all attributes such as name, salaried, payrate, etc..
2. Define a new class for Supervisor. A supervisor is a manager who responds to employees in a specific department. It should
_____________________________________________________________________________________________
#ifndef _EMPLOYEE_H
#define _EMPLOYEE_H
#include <string>
using namespace std;
class Employee {
public:
Employee(string theName, float thePayRate);
string getName() const;
float getPayRate() const;
void setName(string theName);
float pay(float hoursWorked) const;
protected:
string name;
float payRate;
};
Employee::Employee(string theName, float thePayRate)
{
name = theName;
payRate = thePayRate;
}
string Employee::getName() const
{
return name;
}
float Employee::getPayRate() const
{
return payRate;
}
float Employee::pay(float hoursWorked) const
{
return hoursWorked * payRate;
}
#endif /* not defined _EMPLOYEE_H */
_______________________________________________________________________
#ifndef _MANAGER_H
#define _MANAGER_H
#include "Employee.h"
class Manager : public Employee {
public:
Manager(string theName,
float thePayRate,
bool isSalaried);
// Redefine how pay is calculated.
float pay(float hoursWorked) const;
protected:
bool salaried;
};
Manager::Manager(string theName,
float
thePayRate,
bool
isSalaried)
: Employee(theName, thePayRate)
{
salaried = isSalaried;
}
float Manager::pay(float hoursWorked) const
{
if (salaried)
return payRate;
/* else */
return Employee::pay(hoursWorked);
}
#endif /* not defined _MANAGER_H */
_____________________________________________________
* This driver tests the creation and use of employee, manager,
and supervisor objects.
* Don't modify this file!
*/
#include <iostream>
#include "Employee.h"
#include "Manager.h"
#include "Supervisor.h"
using namespace std;
int main()
{
Employee * empl[3]=
{
new Employee ("Alex",
25.0),
new Manager("Beth",
1200.0, true),
new Supervisor ("Cassie",
1000.0, true, "Accounting",250)
};
// Assume all employees worked 40 hours this period, print their
information and payments.
cout << "Their information and payments: \n";
for (int i = 0; i < 3; ++i)
{
empl[i]->print();
cout << "Pay: " <<
empl[i]->pay(40.0) << endl<< endl<<
flush;
}
// Change the names
empl[0]->setName("Alexander");
empl[1]->setName("Elizabeth");
empl[2]->setName("Cassandra");
// Assume all employees' pay rate are changed
empl[0]->setPayRate(50);
for (int i = 1; i < 3; ++i)
empl[i]->setPayRate(1500);
// Assume all employees worked 60 hours this period, print
their information and payments.
cout << "The employee information and payments after
the updates: \n\n";
for (int i = 0; i < 3; ++i)
{
empl[i]->print();
cout << "Pay: " <<
empl[i]->pay(60.0) << endl<< endl<<
flush;
}
return 0;
}
_____________________________________________________________
Sample output
Their information and payments: Name: Alex Pay Rate: 25 Pay: 1000 Name: Beth Pay Rate: 1200 Is salaried? Yes Pay: 1200 Name: Cassie Pay Rate: 1000 Is salaried? Yes Department: Accounting Compensation: 250 Pay: 1250 The information and payments after the updates: Name: Alexander Pay Rate: 50 Pay: 3000 Name: Elizabeth Pay Rate: 1500 Is salaried? Yes Pay: 1500 Name: Cassandra Pay Rate: 1500 Is salaried? Yes Department: Accounting Compensation: 250 Pay: 1750