How to make dependency on inheritance
I'm going to do this exercise:
There are different types of employees: regular employees, managers, board members, which are specific types of controllers
Track the number of objects such as a normal worker.
Each employee has his own first and last name and can introduce himself.
Each employee object has its own employee ID, which is assigned to it while it is created
Wages are calculated in a specific way depending on the type of employee.
Each employee can have his own immediate supervisor, which can be any supervisor (this means that, for example, a council member can be the supervisor of a regular employee)
Now I have done everything except the last point:
class Employees
{
public:
static int workerid;
int salary;
Employees(){
workerid += 1;
}
void introduce(){
cout << "the name is:" << name << "and surname" << surname << endl;
}
};
int Employees::workerid = 0;
class Supervisors :public Employees{
public:
Supervisors(){
salary = 1000;
}
};
class BoardMembers : public Supervisors{
public:
BoardMembers(){
salary = 1200;
}
};
class RegularWorkers :public Employees{
public:
static int number;
Supervisors *supervisor;
RegularWorkers(Supervisors supervisor){
this->supervisor = &supervisor;
number += 1;
salary = 600;
}
};
int RegularWorkers::number = 0;
(I guess until the last point is ok) but for the last point I need one supervisor ID, but how do I get the supervisor or council member to assign a regular worker?
Thanks and best wishes
source to share
Change the employee class by adding Supervisor
Supervisor *supervisor;
And then overload the Employee constructor to take the type Supervisor
and set them equal to each other.
Employees(Supervisor *s){
supervisor = s;
workerid += 1;
}
Then you can access the supervisor id with
supervisor->ID
Also you can include name
and surname
as member variables and initialize them also in the constructor. To add to the previous constructor, it might look like this.
Employees(Supervisor *s, string sName, string sSurname){
name = sName;
surname = sSurname;
supervisor = s;
workerid += 1;
}
source to share