Answer to Question #194093 in C++ for Ajith

Question #194093

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.Runtime Input :

1200

Raja

12500

1200

1500

1800



1
Expert's answer
2021-05-16T12:34:01-0400
#include<iostream>
using namespace std;
class employee{
  public:
    int emp_no;
    char emp_name[25];
    void get(){
      cout<<"enter employee number";
      cin>>emp_no;
      cout<<"enter employee name";
      cin>>emp_name;
    }
};

class salary : public employee{
  float basic_pay,HRA,DA,PF,net_pay;
  public:
    void get1(){
      cout<<"enter the basic pay";
      cin>>basic_pay;
      cout<<"enter HRA";
      cin>>HRA;
      cout<<"Enter DA";
      cin>>DA;
      cout<<"Enter PF";
      cin>>PF;
  }
  void total_payment(){
    net_pay=basic_pay+HRA+DA-PF;
  }
  void display(){
    cout<<emp_no<<"\t"<<emp_name<<"\t"<<basic_pay<<"\t"<<HRA<<"\t"<<DA<<"\t"<<PF<<"\t"<<net_pay<<"\n";
  }
};
int main(){
  int n;
  salary s[10];
  cout<<"enter total no. of employee";
  cin>>n;
  for(int i=0;i<n;i++){
    s[i].get();
    s[i].get1();
    s[i].total_payment();
  }
  cout<<"emp_no \t emp_name \t Basis pay \t HRA \t DA \t PF \t net_payment \n";
  for(int 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