Write a program to compute and print the pay of an employee by using constructor in multiple inheritance with arguments. Pass the employee number and basic pay to constructor, compute the allowances and net pay on basis of basic pay. The program should have the following classes.
◦Emp_address base class
◦Emp_allowance base class
◦Print_pay dervied class which is derived form above mentioned base classes.
#include <string>
#include <iostream>
using namespace std;
class Emp_address
{
public:
Emp_address(int ID, string name, string address);
protected:
int ID;
string name;
string address;
};
Emp_address::Emp_address(int ID, string name, string address)
{
this->ID = ID;
this->address = address;
this->name = name;
}
class Emp_allowance
{
public:
Emp_allowance(double basicPay, double netPay);
protected:
double basicPay;
double netPay;
};
Emp_allowance::Emp_allowance(double basicPay, double netPay)
{
this->basicPay = basicPay;
this->netPay = netPay;
}
class Print_pay : public Emp_allowance, Emp_address
{
public:
Print_pay(int ID, string name, string address, double basicPay, double netPay);
void Display();
};
Print_pay::Print_pay(int ID, string name, string address, double basicPay, double netPay) : Emp_address(ID, name, address), Emp_allowance(basicPay, netPay)
{}
void Print_pay::Display()
{
cout << "Employee ID: " << ID << " Name: " << name << " Address: " << address << " Basic pay: " << basicPay << " Net pay: " << netPay << endl;
}
int main()
{
int ID;
string name, address;
double basicPay, netPay;
cout << "Enter employee ID: ";
cin >> ID;
cout << "Enter employee name: ";
cin >> name;
cout << "Enter emplyee address: ";
cin.ignore();
getline(cin, address);
cout << "Enter emplyee net pay: ";
cin >> netPay;
cout << "Enter employee basic pay: ";
cin >> basicPay;
Print_pay employee(ID, name, address, basicPay, netPay);
cout << "*****You entered*****" << endl;
employee.Display();
system("pause");
return 0;
}
Comments
Leave a comment