Answer to Question #185885 in C++ for VARUN

Question #185885

Reusability using inheritance


Design a pay roll system to find the employee total salary using single inheritance. The base class employee consisting of data members such as emp_number and emp_name. The derived class salary consisting of data members such as Basic_pay, HRA, DA, PF, Net_pay.


run time input

1200

raja

12500

1200

1500

1800

output should

1200

raja

12500

1200

1500

1800

17000


1
Expert's answer
2021-04-28T02:48:54-0400
#include<iostream>
using namespace std;

class employee
{
   public:
     int e_id;
     char name[20],designation[20];
     void get()
     {
              cout<<"Enter employee ID:";
              cin>>e_id;
              cout<<"Name of Employee:";
              cin>>name;
              cout<<"Degination:";
              cin>>designation;
     }
};
class salaryCalc:public employee
{
     float basicPay,hra,da,pf,np;
   public:
     void get1()
     {
              cout<<"Enter the basic pay:";
              cin>>basicPay;
              cout<<"Enter the Human Resource Allowance:";
              cin>>hra;
              cout<<"Enter the Dearness Allowance :";
              cin>>da;
              cout<<"Enter the provisional Fund:";
              cin>>pf;
     }
     void calculate()
     {
              np=basicPay+hra+da-pf;
     }
     void display()
     {
              cout<<e_id<<"\t"<<name<<"\t"<<designation<<"\t"<<basicPay<<"\t"<<hra<<
              "\t"<<da<<"\t"<<pf<<"\t"<<np<<"\n";
     }
};
int main()
{
    int i,n;
    char ch;
    salaryCalc s[10];

    cout<<"Total number of employee in the organization:";
    cin>>n;
    for(i=0;i<n;i++)
    {
              s[i].get();
              s[i].get1();
              s[i].calculate();
    }
    cout<<"\e_id \t Name\t Des \t BPay \t hra \t da \t pf \t np \n";
    for(i=0;i<n;i++)

    {
              s[i].display();
    }

return 0;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS