The classes in this lab describe a superclass named EmployeePerson and two deriv
ID: 3914967 • Letter: T
Question
The classes in this lab describe a superclass named EmployeePerson and two derived classes, EmployeeManager and EmployeeStaff, each of which extends the EmployeePerson class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. Specifications Define the EmployeeManager and EmployeeStaff classes in EmployeeManager.cpp and EmployeeStaff.cpp respectively. Make the EmployeeStaff class override the EmployeePerson class' PrintInfo function and print all the fields from the EmployeeStaff class. Make the EmployeeManager class override the EmployeePerson class' printInfo function and print all the fields from the EmployeeManager class. Run the program and verify the output includes the manager and staff information. Required Employee interfaces EmployeePerson.h and EmployeePerson.cpp contain the EmployeePerson class declaration and definition. EmployeeManager.h and EmployeeStaff.h contain the EmployeeManager and EmployeeStaff class declarations. Use these to create the class definitions in EmployeeManager.cpp and EmployeeStaff.cpp. The EmployeePerson.h, EmployeePerson.cpp, EmployeeManager.h, and EmployeeStaff.h files cannot be changed. The main() function The main() function to test your classes is in EmployeeMain.cpp and cannot be changed. For the main() function given, the output is: Name: Michele, Department: Sales, Birthday: 03-03-1975, Salary: 70000, Staff managed: 25 Name: Bob, Department: Sales, Birthday: 02-02-1980, Salary: 50000, Manager: Michele
Explanation / Answer
EmployeeMain.cpp
#include "EmployeeManager.h"
#include "EmployeeStaff.h"
int main()
{
EmployeeManager m("Tom","Purchase","05-10-1970",200000,20); //Object created for manager class
EmployeeStaff s("Robert","Purchase","30-01-1980",40000,"Tom"); //Object created for staff class
EmployeePerson *e[2];
e[0]=&m; //manager object is pointed by base class
e[1]=&s; //staff object is pointed by base class
e[0]->printInfo(); //prints the manager information
e[1]->printInfo(); //prints the staff information
return 0;
}
EmployeePerson.h:
#ifndef MYHEADER_H
#define MYHEADER_H
#include <iostream>
#include <string>
using namespace std;
//base class
class EmployeePerson
{
public:
EmployeePerson(string theName, string theDepartment, string theBirthDay, int theSalary);
string getName() const;
string getDepartment() const;
string getBirthDay() const;
int getSalary() const;
virtual void printInfo()=0; //pure virtual function printInfo
protected:
string name;
string depart;
string bDay;
int sal;
};
#endif
EmployeePerson.cpp:
#include "EmployeePerson.h"
EmployeePerson::EmployeePerson(string theName, string theDepartment, string theBirthDay, int theSalary)
{
name = theName;
depart = theDepartment;
bDay = theBirthDay;
sal = theSalary;
}
string EmployeePerson::getName() const { return name; }
string EmployeePerson::getDepartment() const{ return depart; }
string EmployeePerson::getBirthDay() const{ return bDay; }
int EmployeePerson::getSalary() const{ return sal; }
EmployeeManager.h:
#include "EmployeePerson.h"
class EmployeeManager : public EmployeePerson
{
public:
EmployeeManager(string theName, string theDepartment, string theBirthDay, int theSalary, int theTotStaffManaged);
int getTotStaffManaged() const;
void printInfo();
protected:
int totStaffManaged;
};
EmployeeManager.cpp:
#include "EmployeeManager.h"
//new member field total staff managed added along with inherited fields from base class
EmployeeManager::EmployeeManager(string theName, string theDepartment, string theBirthDay, int theSalary, int theTotStaffManaged): EmployeePerson(theName, theDepartment, theBirthDay, theSalary)
{
totStaffManaged = theTotStaffManaged;
}
//returns the total staff managed
int EmployeeManager::getTotStaffManaged() const { return totStaffManaged; }
//function to print the manager information
void EmployeeManager::printInfo()
{
cout<<"Name: "<<name<<endl;
cout<<"Department: "<<depart<<endl;
cout<<"Birthday: "<<bDay<<endl;
cout<<"Salary: "<<sal<<endl;
cout<<"Staff Managed: "<<totStaffManaged<<endl;
}
EmployeeStaff.h:
#include "EmployeePerson.h"
class EmployeeStaff : public EmployeePerson
{
public:
EmployeeStaff(string theName, string theDepartment, string theBirthDay, int theSalary, string theManager);
string getManager() const;
void printInfo();
protected:
string manager;
};
EmployeeStaff.cpp:
#include "EmployeeStaff.h"
//new member field manager added along with inherited fields from base class
EmployeeStaff::EmployeeStaff(string theName, string theDepartment, string theBirthDay, int theSalary, string theManager)
: EmployeePerson(theName, theDepartment, theBirthDay, theSalary)
{
manager = theManager;
}
//returns the manager of the staff
string EmployeeStaff::getManager() const{ return manager; }
//function to print the staff information
void EmployeeStaff::printInfo()
{
cout<<"Name: "<<name<<endl;
cout<<"Department: "<<depart<<endl;
cout<<"Birthday: "<<bDay<<endl;
cout<<"Salary: "<<sal<<endl;
cout<<"Manager: "<<manager<<endl;
}
Output:
Name: Tom
Department: Purchase
Birthday: 05-10-1970
Salary: 200000
Staff Managed: 20
Name: Robert
Department: Purchase
Birthday: 30-01-1980
Salary: 40000
Manager: Tom
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.