Simple Example Program With Inheritance Base Class Private Member
// Header Files
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
class Employee {
int eno;
char name[20], des[20];
// Private members cannot call from outside class.
public:
void getEmpDetails() {
cout << "\nEnter the Employee number:";
cin>>eno;
cout << "Enter the Employee name:";
cin>>name;
cout << "Enter the Employee designation:";
cin>>des;
}
void employee_display() {
cout <<"\nEmployee number:"<<eno;
cout <<"\nEmployee name:"<<name;
cout <<"\nEmployee designation:"<<des;
}
};
class Salary : public Employee {
//We cannot use Employee Base Class Private Members
float bp, hra, da, pf, np;
public:
void getPayDetails() {
cout << "Enter the Basic pay:";
cin>>bp;
cout << "Enter the Humen Resource Allowance:";
cin>>hra;
cout << "Enter the Dearness Allowance :";
cin>>da;
cout << "Enter the Profitablity Fund:";
cin>>pf;
}
void calculate() {
np = bp + hra + da - pf;
}
void display() {
employee_display();
cout <<"\nEmployee Basic pay:"<<bp;
cout <<"\nEmployee Humen Resource Allowance:"<<hra;
cout <<"\nEmployee Dearness Allowance:"<<da;
cout <<"\nEmployee Profitablity Fund:"<<pf;
cout <<"\nEmployee Net Pay:"<<np<<endl;
}
};
int main() {
int i, n;
char ch;
Salary s[10];
cout << "Simple Inheritance Base Class Private Member : Payroll System \n";
cout << "Enter the number of employee:";
cin>>n;
for (i = 0; i < n; i++) {
cout << "\nEmployee Details # "<<(i+1)<<" : ";
s[i].getEmpDetails();
s[i].getPayDetails();
s[i].calculate();
}
for (i = 0; i < n; i++) {
s[i].display();
}
getch();
return 0;
}
Sample Output
Simple Inheritance Base Class Private Member : Payroll System
Enter the number of employee:2
Employee Details # 1 :
Enter the Employee number:1
Enter the Employee name:BALU
Enter the Employee designation:SE
Enter the Basic pay:10000
Enter the Humen Resource Allowance:1000
Enter the Dearness Allowance :500
Enter the Profitablity Fund:600
Employee Details # 2 :
Enter the Employee number:2
Enter the Employee name:SUMESH
Enter the Employee designation:SX
Enter the Basic pay:12000
Enter the Humen Resource Allowance:1100
Enter the Dearness Allowance :600
Enter the Profitablity Fund:600
Employee number:1
Employee name:BALU
Employee designation:SE
Employee Basic pay:10000
Employee Humen Resource Allowance:1000
Employee Dearness Allowance:500
Employee Profitablity Fund:600
Employee Net Pay:10900
Employee number:2
Employee name:SUMESH
Employee designation:SX
Employee Basic pay:12000
Employee Humen Resource Allowance:1100
Employee Dearness Allowance:600
Employee Profitablity Fund:600
Employee Net Pay:13100
--------------------------------
Process exited after 105.4 seconds with return value 0
Press any key to continue . . .