Define the classes using hierarchy inheritance. An organization has two types of employees: Regular and Adhoc are derived class. Regular employees get a salary which is Basic salary + DA + HRA where DA is 10% of basic and HRA is 30% of basic. Adhoc employees are daily wagers who get a salary which is equal to Number oh hours * Wages amount. The employee base class consisting of member variables such as name and empid. When a regular employee is created, basic salary must be a parameter. When Adhoc employee is created wages amount must be a parameter. Define the member functions for each class and the member function days( ) updates number of the Adhoc employee
#include <iostream>
#include <string>
using namespace std;
class Employee
{
//The employee base class consisting of member variables such as name and empid
private:
string name;
int empid;
public:
Employee(){
}
virtual float salary(){
return 0;
}
void setName(string name){
this->name=name;
}
void setEmpid(int empid){
this->empid=empid;
}
};
class Regular :public Employee{
private:
float basic;
public:
Regular(float basic){
this->basic=basic;
}
//Regular employees get a salary which is Basic salary + DA + HRA where DA is 10% of basic and HRA is 30% of basic.
float salary(){
float DA=basic*0.1;
float HRA=basic*0.3;
return basic+ DA + HRA;
}
};
class Adhoc:public Employee{
private:
int number;
float wagesAmount;
public:
Adhoc(float wagesAmount){
this->wagesAmount=wagesAmount;
}
float salary(){
return number*wagesAmount;
}
//the member function days( ) updates number of the Adhoc employee
void days(int n){
this->number=n;
}
};
int main(){
//When a regular employee is created, basic salary must be a parameter.
Regular regularEmployee(5000);
regularEmployee.setName("Peter");
regularEmployee.setEmpid(15452);
cout<<"The salary of Regular employee: "<<regularEmployee.salary()<<"\n";
//When Adhoc employee is created wages amount must be a parameter.
Adhoc adhocEmployee(40);
adhocEmployee.setName("Mary");
adhocEmployee.setEmpid(2565);
adhocEmployee.days(12);
cout<<"The salary of Adhoc employee: "<<adhocEmployee.salary()<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment