USING C++ VISUAL STUDIO COMPILER PLEASE SOLVE ASSIGNMENT FULLY FOR BEST ANSWER S
ID: 663745 • Letter: U
Question
USING C++ VISUAL STUDIO COMPILER PLEASE SOLVE ASSIGNMENT FULLY FOR BEST ANSWER SHOW OUTPUT
Objective:
To gain experience on creating derived classes and inheritance.
Project Description
Take the code we've provided for the Employee class (Employee.h) and the Manager class (Manager.h).
Add methods to the classes named:
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?
CREATE Supervisor.h header file
Your code should compile and run correctly with the test program: Empltest.cpp.
THIS IS MY SUPERVISOR.H FILE SO FAR IT HAS SOME ERRORS AND WONT COMPILE PROPERLY WITH THE .CPP PROVIDED. I NEED to add methods to the class names setName() setPayRate() and setSalaried()
Here is my SUPERVISOR.h file
#ifndef _SUPERVISOR_H
#define _SUPERVISOR_H
#include "employee.h"
class Supervisor : public Manager {
public:
Supervisor(string name, float salary, string dept);
string getDept();
void setDept(string s);
float pay();
private:
string dept;
float salary;
};
Supervisor::Supervisor(string name, float salary, string dep):Manager(name, salary,true){
dept = dep;
}
Supervisor::setDept(string s){
dept = s;
}
Supervisor::getDept(){
return dept;
}
Explanation / Answer
File : EmplTest.cpp
#include "stdafx.h"
#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() << endl;
cout << "Dept: " << sup.getDept() << endl;
cout << "Changing the Supervisor's pay rate..." << endl;
sup.setPayRate(900.0);
cout << "New Pay: " << sup.pay() << endl;
system("pause");
return 0;
}
File : Supervisor.h
#ifndef _SUPERVISOR_H
#define _SUPERVISOR_H
#include "employee.h"
class Supervisor : public Manager {
public:
Supervisor(string name, float salary, string dept);
string getDept();
void setDept(string s);
float pay();
void setPayRate(float salary);
private:
string dept;
float salary;
};
Supervisor::Supervisor(string name, float salary, string dep) :Manager(name, salary, true){
dept = dep;
}
void Supervisor::setDept(string s){
dept = s;
}
string Supervisor::getDept(){
return dept;
}
void Supervisor::setPayRate(float s)
{
salary = s;
}
float Supervisor::pay()
{
return salary;
}
#endif
File : 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;
void setSalaried(bool val);
protected:
bool salaried;
};
//Manager method definitions.
void Manager::setSalaried(bool val)
{
salaried = val;
}
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);
}
#endif // not defined _MANAGER_H
File : employee.h
#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;
void setName(string s);
protected:
string name;
float payRate;
};
/*
* Employee method definitions.
*/
void Employee::setName(string s)
{
name = s;
}
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 */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.