Please write in C++ language and provide comments to explain your answers. Probl
ID: 3596813 • Letter: P
Question
Please write in C++ language and provide comments to explain your answers.
Problem Description We want to create a C++ system that manages the employees of a pharmaceutical database. The database 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 the 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).
Q1. [50 marks] Create the classes needed to model the employees of the pharmaceutical database. 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 function
Q2. [50 marks] We want to create a class, called EmployeeDB, to keep track of the employees defined in Q1. The class EmployeeDB stores the employee ID as its index and has the following attributes: name (string) address (string), list of employees (an array of objects of the Employee class), and number of employees the database has (int). Provide the definition and implementation of the class EmployeeDB. The class must implement the following functions:
• A default constructor, a regular constructor, a copy constructor, a destructor
• Accessing functions
• A function that insert an employee to the database (message should show if the employee already exists)
• A function that removes an employee from the company (message should show if the employee already exists)
• A function that returns the number of employees of the company
• A function that returns the list (names) of the employees
• A function that returns the information of an employee given the employee id
Explanation / Answer
Q1. i am giving you only the first question answer
#include<iostream>
#include<string>
using namespace std;
class Employee{
protected:
int employeeId;
string name;
string position;
int seniority;
public:
Employee(){
employeeId = 0;
name = " ";
position = " ";
seniority = 0;
}
Employee(int i,string n,string p,int s){
employeeId = i;
name = n;
position = p;
seniority = s;
}
Employee(const Employee &e){
this->employeeId = e.employeeId;
this->name = e.name;
this->position = e.position;
this->seniority = e.seniority;
}
~Employee(){
delete this;
}
int getId(){
return employeeId;
}
string getName(){
return name;
}
string getPosition(){
return position;
}
int getSeniority(){
return seniority;
}
void showEmployee(){
cout<<" Employee Id = "<<this->employeeId;
cout<<" Employee Name = "<<this->name;
cout<<" Employee Position = "<<this->position;
cout<<" Employee Seniority = "<<this->seniority;
}
};
class Administrator:public Employee{
protected:
int noOfEmployee;
public:
Administrator(){
noOfEmployee = 0;
Employee();
}
Administrator(int noe,int i,string n,string p,int s){
noOfEmployee = noe;
Employee(i,n,p,s);
}
Administrator(const Administrator &a){
this->noOfEmployee = a.noOfEmployee;
this->employeeId = a.employeeId;
this->name = a.name;
this->position = a.position;
this->seniority = a.seniority;
}
~Administrator(){
delete this;
}
int getNoOfEmployee(){
return noOfEmployee;
}
void showAdministrator(){
showEmployee();
cout<<" No Of Employee = "<<this->noOfEmployee;
}
};
class Researcher:public Employee{
protected:
string title;
string area;
public:
Researcher (){
title = " ";
area = " ";
Employee();
}
Researcher(string t,string a,int i,string n,string p,int s){
title = t;
area = a;
Employee(i,n,p,s);
}
Researcher(const Researcher &a){
this->title = a.title;
this->area = a.area;
this->employeeId = a.employeeId;
this->name = a.name;
this->position = a.position;
this->seniority = a.seniority;
}
~Researcher(){
delete this;
}
string getTitle(){
return title;
}
string getArea(){
return area;
}
void showResearcher(){
showEmployee();
cout<<" Title = "<<this->title;
cout<<" Area = "<<this->area;
}
};