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 {
//statement
}
class Peon {
//statement
}
class Admin : public Clerk, public Peon {
//statement
}
Example: How to calculate employee salary using multiple inheritance in C++.
#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 << "Enter Peon salary:";
cin>>psal;
}
};
class Admin : public Clerk, public Peon {
public:
int tsal;
void findSal() {
tsal = csal + psal;
cout << "Total salary is:" << tsal;
}
};
int main() {
Admin obj;
obj.input1();
obj.input2();
obj.findSal();
return 0;
}
Output:
Enter Clerk salary:1000
Enter Peon salary:2000
Total salary is:3000