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.
( Reusability using inheritance )
#include<iostream>
using namespace std;
class employee
{
protected:
char name;
int emp_id;
public:
void get_name();
void get_emp_id()
{
cout<<"Enter the name of the employee:"<<endl;
cin>>name;
cout<<"Enter the emp_id of the employee:"<<endl;
cin>>emp_id;
}
};
class normal_pay: public employee
{
protected:
double basic_salary;
public:
void get_basic_salary()
{
cout<<"Enter the basic salary:"<<endl;
cin>>basic_salary;
}
};
class additional_pay
{
protected:
int hours;
int rupees;
int additional_pay;
public:
void get_hours();
void get_rupees();
void get_additional_pay()
{
cout<<"Enter hours rupees and additional pay:"<<endl;
cin>>hours>>rupees>>additional_pay;
}
};
class netpay : public normal_pay , public additional_pay
{
protected:
int total_salary;
public:
void total()
{
get_additional_pay();
get_basic_salary();
cout<<"total salary: "<<basic_salary + additional_pay<<endl;
}
};
int main(){
netpay total_salary;
total_salary.total();
return 0;
}
Comments
Leave a comment