Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Take the code we\'ve provided for the Employee class (Employee.h and the Manager

ID: 3907968 • Letter: T

Question

Take the code we've provided for the Employee class (Employee.h

and the Manager class (Manager.h

Add methods to the classes named:

setName()

setPayRate()

setSalaried()

that let users change the corresponding fields. Take advantage of the inheritance relationship between Employee and Manager--you only need to add each of those methods to 1 class.

Write a Supervisor class. A supervisor is responsible for employees in a specific department and must:

Have a field to store the department name (as a string).

Have getDept() and setDept() methods to access the department field.

Always be salaried (i.e., pay for a single pay period is fixed, no matter how many hours are worked).

Have a constructor that takes initial values for all fields.

What class should Supervisor inherit from?

Your code should compile and run correctly with the test program: Empltest.cpp

.

Upload- your source files: Employee.h, Manager.h, and new file Supervisor.h)

***************************************************************************************************************************************************

employee.h

/*

* File: employee.h

* Employee class definition.

*/

#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;

float pay(float hoursWorked) const;

protected:

string name;

float payRate;

};

/*

* Employee method definitions.

*/

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 */

***************************************************************************************************************************************************

manager.h

//File: manager.h

//Manager class definition.

#ifndef _MANAGER_H

#define _MANAGER_H

#include "employee.h"

class Manager : public Employee {

public:

Manager(string theName,

float thePayRate,

bool isSalaried);

bool getSalaried() const;

float pay(float hoursWorked) const;

protected:

bool salaried;

};

//Manager method definitions.

Manager::Manager(string theName,

float thePayRate,

bool isSalaried)

: Employee(theName, thePayRate)

{

salaried = isSalaried;

}

bool Manager::getSalaried() const

{

return salaried;

}

float Manager::pay(float hoursWorked) const

{

if (salaried)

return payRate;

// else

return Employee::pay(hoursWorked);

}

***************************************************************************************************************************************************

empltest.cpp

/*

* File: Empltest.cpp

* This program illustrates the creation and use of employee objects.

*/

#include <iostream>

#include "Employee.h"

#include "Manager.h"

#include "Supervisor.h"

using namespace std;

int main()

{

Employee empl("John", 25.0);

Manager mgr("Matthew", 1200.0, true);

Supervisor sup("Denise", 780.0, "Accounting");

// Assume all employees worked 40 hours this period.

cout << "For Employee:" << endl;

cout << "Name: " << empl.getName() << endl;

cout << "Pay: " << empl.pay(40.0) << endl;

cout << "Changing the Employee's name..." << endl;

empl.setName("Doug");

cout << "New Name: " << empl.getName() << endl;

cout << endl;

cout << "For Manager:" << endl;

cout << "Name: " << mgr.getName() << endl;

cout << "Salaried: " << mgr.getSalaried() << endl;

cout << "Pay: " << mgr.pay(40.0) << endl;

cout << "Changing the Manager's salaried status..." << endl;

mgr.setSalaried(false);

cout << "New Pay: " << mgr.pay(40.0) << endl;

cout << endl;

cout << "For Supervisor:" << endl;

cout << "Name: " << sup.getName() << endl;

cout << "Pay: " << sup.pay(40.0) << endl;

cout << "Dept: " << sup.getDept() << endl;

cout << "Changing the Supervisor's pay rate..." << endl;

sup.setPayRate(900.0);

cout << "New Pay: " << sup.pay(40.0) << endl;

return 0;

}

Please add comments in the cod

Explanation / Answer

employee.h

/*
* File: employee.h
* Employee class definition.
*/
#ifndef _EMPLOYEE_H
#define _EMPLOYEE_H
#include <string>
using namespace std;
class Employee {
public:
Employee(string theName, float thePayRate);
string getName() const;
void setName(string a);
float getPayRate() const;
void setPayRate(double a);
float pay(float hoursWorked) const;
protected:
string name;
float payRate;
};
/*
* Employee method definitions.
*/
Employee::Employee(string theName, float thePayRate)
{
name = theName;
payRate = thePayRate;
}
string Employee::getName() const
{
return name;
}
void Employee::setName(string a)
{
   name = a;
}
float Employee::getPayRate() const
{
return payRate;
}

void Employee::setPayRate(double a)
{
    payRate = a;
}
float Employee::pay(float hoursWorked) const
{
return hoursWorked * payRate;
}
#endif /* not defined _EMPLOYEE_H */

manager.h

//File: manager.h
//Manager class definition.
#ifndef _MANAGER_H
#define _MANAGER_H
#endif
//#include "employee.h"
class Manager : public Employee {
public:
Manager(string theName,
float thePayRate,
bool isSalaried);
bool getSalaried() const;
void setSalaried(bool a);
float pay(float hoursWorked) const;
protected:
bool salaried;
};
//Manager method definitions.
Manager::Manager(string theName,
float thePayRate,
bool isSalaried)
: Employee(theName, thePayRate)
{
salaried = isSalaried;
}
bool Manager::getSalaried() const
{
return salaried;
}

void Manager::setSalaried(bool a)
{
   salaried = a;
}
float Manager::pay(float hoursWorked) const
{
if (salaried)
return payRate;
// else
return Employee::pay(hoursWorked);
}

Supervisor.h

class Supervisor : public Manager{

    private:
       string dept;
    public:
       Supervisor(string n, double d, string dp): Manager(n,d,true){
          dept = dp;
       }
       string getDept(){
           return dept;
       }
       string setDept(string a){
           dept = a;;
       }
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote