Develop a code for the hybrid Inheritance diagram given below
· The employee details class consisting of data members such as name and emp_id.
· The normal pay class consisting of data members such as basic salary.
· The additional pay class consisting of data members such as hours, rupees and additional pay.
· The net pay class consisting of member function cal() to find the employee total salary = additional pay + basic salary.
#include<iostream>
using namespace std;
class Employee
{
protected:
string emp_name;
int emp_id;
public:
void get_emp_details()
{
cout<<"Enter the name of the employee: "<<endl;
cin>>emp_name;
cout<<"Enter the employee ID: "<<endl;
cin>>emp_id;
}
string display_employee_name()
{
return emp_name;
}
int display_employee_id()
{
return emp_id;
}
};
class NormalPay: public Employee
{
protected:
double basic_salary;
public:
void get_basic_salary()
{
cout<<"Enter the basic salary: "<<endl;
cin>>basic_salary;
}
};
class AdditionalPay
{
protected:
double hours;
double rupees;
double additional_pay;
public:
void get_additional_pay()
{
cout<<"Enter rupees payment per additional hour: "<<endl;
cin>>rupees;
cout<<"Enter additional hours worked: "<<endl;
cin>>hours;
}
void calc_additional_pay()
{
additional_pay = hours * rupees;
}
double display_additional_pay()
{
return additional_pay;
}
};
class NetPay : public NormalPay , public AdditionalPay
{
protected:
int total_salary;
public:
double calc()
{
total_salary = basic_salary + additional_pay;
}
double display_total_pay()
{
return total_salary;
}
};
int main(){
//Create NetPay class object
NetPay pay1;
pay1.get_emp_details();
pay1.get_basic_salary();
pay1.get_additional_pay();
pay1.calc_additional_pay();
pay1.calc();
//Summary
cout<<"Employee name: \t"<<pay1.display_employee_name()<<endl;
cout<<"Employee ID: \t"<<pay1.display_employee_id()<<endl;
cout<<"Additional Pay: "<<pay1.display_additional_pay()<<endl;
cout<<"Total salary: \t"<<pay1.display_total_pay()<<endl;
return 0;
}
Comments
Leave a comment