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)
Runtime Input :
Rajesh
1101
10000
10
50
Output :
Rajesh
1101
10000
10
50
500
10500
#include <iostream>
#include <string>
using namespace std;
class Employee
{
public:
void setName(string n)
{
name = n;
}
void setEmpId(int emp)
{
emp_id = emp;
}
string getName()
{
return name;
}
int getEmpId()
{
return emp_id;
}
private:
string name;
int emp_id;
};
class NormalPay:public Employee
{
public:
void setSalary(double pay)
{
basic_salary = pay;
}
double getSalary()
{
return basic_salary;
}
private:
double basic_salary;
};
class AdditionalPay :public Employee
{
public:
void setHours(double hour)
{
hours = hour;
}
double getHours()
{
return hours;
}
void setRupies(double rupie)
{
rupies = rupie;
}
double getRupies()
{
return rupies;
}
void setAddPay(double pay)
{
add_pay = pay;
}
double getAddPay()
{
add_pay = hours * rupies;
return add_pay;
}
private:
double hours;
double rupies;
double add_pay;
};
class NetPay:public NormalPay,public AdditionalPay
{
public:
double cal() {
total_salary = getAddPay() + getSalary();
return total_salary;
}
private:
double total_salary;
};
int main()
{
NetPay example;
string name;
double pay;
double hour;
double rupie;
int emp_id;
// input data
cout << "Emploee id ";
cin >> emp_id;
example.NormalPay::setEmpId(emp_id);
cout <<"Enter name ";
cin >> name;
example.NormalPay::setName(name);
cout << "Enter basic salary ";
cin >> pay;
example.setSalary(pay);
cout << "Enter additional hour ";
cin >> hour;
example.setHours(hour);
cout << "Enter rupies ";
cin >> rupie;
example.setRupies(rupie);
// output data
cout << "Emploe Id;" << example.NormalPay::getEmpId() << endl;
cout << "Name" << example.NormalPay::getName() << endl;
cout << " Basic salary" << example.getSalary()<<endl;
cout << " Additional salary" << example.getAddPay()<<endl;
cout << " Total salary" << example.cal()<<endl;
return 0;
}
Comments
Leave a comment