the student should use INHERITANCE and POLYMORHISM . We want to create a C++ sys
ID: 3793182 • Letter: T
Question
the student should use INHERITANCE and POLYMORHISM.
We want to create a C++ system that manages the employees of a pharmaceutical company. The company has two types of employees: Researchers and Administrators. Both types of employees have the following properties, employee id (int), name (string), position (string), seniority (int). In addition, researchers have die following attributes: title (string) and area of expertise (string). Administrative employees have the following additional attributes: number of employees that are managed by the employee (int). Create the classes needed to model the employees of the pharmaceutical company. It is up to you to decide how many classes are needed. You must also decide about which functions should be virtual, constant, etc. You need to provide both a class definition and implementation. Each class must have at least the following functions: A default constructor, a regular constructor, a copy constructor, a destructor Accessing functions A print functionExplanation / Answer
#include <iostream>
using namespace std;
class Employees //base abstract class
{
private:
int employeeId;
string name;
string position;
int seniority;
public:
Employees() //default constructor
{
this->employeeId = 0;
this->name = "";
this->position = "";
this->seniority = 0;
}
Employees(int employeeId,string name,string position,int seniority) //parameterized constructor
{
this->employeeId = employeeId;
this->name = name;
this->position = position;
this->seniority = seniority;
}
Employees(const Employees &emp)//copy constructor
{
employeeId = emp.employeeId;
name = emp.name;
position = emp.position;
seniority = emp.seniority;
}
~Employees() //destructor
{
cout<<" Employee destructor";
}
int getEmployeeID() //get methods
{
return employeeId;
}
string getName()
{
return name;
}
string getPosition()
{
return position;
}
int getSeniority()
{
return seniority;
}
virtual void print() = 0; //pure virtual function
};
class Researchers: Employees
{
private:
string title;
string expertiseArea;
public:
Researchers()
{
this->title = "";
this->expertiseArea = "";
}
Researchers(int employeeId,string name,string position,int seniority,string title,string expertiseArea):Employees(employeeId,name,position,seniority)
{
this->title = title;
this->expertiseArea = expertiseArea;
}
Researchers(const Researchers &r)
{
title = r.title;
expertiseArea = r.expertiseArea;
}
~Researchers()
{
cout<<" Researcher destructor";
}
string getTitle()
{
return title;
}
string getExpertiseArea()
{
return expertiseArea;
}
void print() //overriding base class function
{
cout<<" Employee Id: "<<getEmployeeID()<<" Name : "<<getName()<<" Position : "<<getPosition()<<" Seniority : "<<getSeniority()<<" Title : "<<getTitle()<<" Expertise Area : "<<getExpertiseArea();
}
};
class Administrators: Employees
{
private:
int employeesManaged;
public:
Administrators()
{
this->employeesManaged = 0;
}
Administrators(int employeeId,string name,string position,int seniority,int employeesManaged):Employees(employeeId,name,position,seniority)
{
this->employeesManaged = employeesManaged;
}
Administrators(const Administrators &a)
{
employeesManaged = a.employeesManaged;
}
~Administrators()
{
cout<<" Administrator destructor";
}
int getEmployeesManaged()
{
return employeesManaged;
}
void print()
{
cout<<" Employee Id: "<<getEmployeeID()<<" Name : "<<getName()<<" Position : "<<getPosition()<<" Seniority : "<<getSeniority()<<" Number of Employees managed : "<<getEmployeesManaged();
}
};
int main()
{
Researchers r(1001,"John Fisher","Atomicity",3,"Mr","Physics");
Administrators a(1002,"John Fisher","Physics",3,150);
r.print();
a.print();
return 0;
}
output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.