Simple Inheritance Private Base Class Example Program
Example Program on Simple with Private Base Class
// 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 : private Employee {
//Private Base Class, We cannot access outside the dervied Class
float bp, hra, da, pf, np;
public:
void getPayDetails() {
getEmpDetails();
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 Private Base Class Example Program : Payroll System \n";
cout << "Enter the number of employee:";
cin>>n;
for (i = 0; i < n; i++) {
cout << "\nEmployee Details # "<<(i+1)<<" : ";
//getEmpDetails(); inaccessible from outside derived class, Which is private Base Class.
s[i].getPayDetails();
s[i].calculate();
}
for (i = 0; i < n; i++) {
s[i].display();
}
getch();
return 0;
}
Output
Simple Inheritance Private Base Class Example Program : Payroll System
Enter the number of employee:2
Employee Details # 1 :
Enter the Employee number:1
Enter the Employee name:BOSE
Enter the Employee designation:DOC
Enter the Basic pay:20000
Enter the Humen Resource Allowance:2000
Enter the Dearness Allowance :1000
Enter the Profitablity Fund:800
Employee Details # 2 :
Enter the Employee number:2
Enter the Employee name:AMZE
Enter the Employee designation:FIN
Enter the Basic pay:15000
Enter the Humen Resource Allowance:1200
Enter the Dearness Allowance :1200
Enter the Profitablity Fund:900
Employee number:1
Employee name:BOSE
Employee designation:DOC
Employee Basic pay:20000
Employee Humen Resource Allowance:2000
Employee Dearness Allowance:1000
Employee Profitablity Fund:800
Employee Net Pay:22200
Employee number:2
Employee name:AMZE
Employee designation:FIN
Employee Basic pay:15000
Employee Humen Resource Allowance:1200
Employee Dearness Allowance:1200
Employee Profitablity Fund:900
Employee Net Pay:16500
--------------------------------
Process exited after 57.27 seconds with return value 0
Press any key to continue . . .
Inheritance In C++ Programs
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Inheritance Base Class Private Member Example Program
- Simple Inheritance Private Base Class Example Program
- Simple Multi Level Inheritance Example Program
- Simple Hierarchical Inheritance Example Program
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor Overloading In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Example Program For Constructor In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Exception Handling Divide by zero Using C++ Programming