C++ Program to calculate employee salary using multiple inheritance


In this program, You will learn how to calculate employee salary using multiple inheritance in C++.


class Clerk { }

class Peon { }

class Admin : public Clerk, public Peon { }


Example: How to calculate employee salary using multiple inheritance in C++

Run it Now
#include<iostream>
using namespace std;

class Clerk {
public:
   int csal;

   void input1() {
       cout << "Enter Clerk salary :";
       cin>>csal;
   }
};

class Peon {
public:
   int psal;

   void input2() {
       cout << "\nEnter Peon salary :";
       cin>>psal;
   }
};

class Admin : public Clerk, public Peon {
public:
   int tsal;

   void findSal() {
       tsal = csal + psal;
       cout << "\nTotal salary is :" << tsal;
   }
};

int main() {

   Admin obj;
   obj.input1();
   obj.input2();
   obj.findSal();

   return 0;
}

Output:

Enter Clerk salary :10000
Enter Peon salary :8000
Total salary is :18000