Write A Program for Multi level Inheritance Using C++ Programming


Write A Program for Multi level Inheritance Using C++ Programming

#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;
        calculate();
    }

    void calculate() {
        np = bp + hra + da - pf;
    }

    void salary_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;
    }
};

class BankCredit : private Salary {
          char bank[20], ifsc_code[20];  
          int account_number;
          public:
          void getBankDetails() {
          getPayDetails();
        cout << "Enter the Bank Name:";
        cin>>bank;
        cout << "Enter the IFSC:";
        cin>>ifsc_code;
        cout << "Enter the Account Number :";
        cin>>account_number;
    }
   
    void display() {
          salary_display();
          cout <<"\nEmployee Bank Name:"<<bank;
                   cout <<"\nEmployee IFSC:"<<ifsc_code;
                   cout <<"\nEmployee Account Number:"<<account_number<<endl;
    }
};

int main() {
    int i, n;
    char ch;
    BankCredit s[10];
    cout << "Simple Multi Level Inheritance Example Program : Payroll System \n";
    cout << "Enter the number of employee:";
    cin>>n;
    for (i = 0; i < n; i++) {
          cout << "\nEmployee Details # "<<(i+1)<<" : ";
        s[i].getBankDetails();
    }

    for (i = 0; i < n; i++) {
        s[i].display();
    }
    getch();
   
    return 0;
}
OUTPUT:-

Simple Multi Level Inheritance Example Program : Payroll System
Enter the number of employee:2

Employee Details # 1 :
Enter the Employee number:101
Enter the Employee name:MASTE
Enter the Employee designation:Er
Enter the Basic pay:26000
Enter the Humen Resource Allowance:1300
Enter the Dearness Allowance :1200
Enter the Profitablity Fund:500
Enter the Bank Name:SBI
Enter the IFSC:ISFC001
Enter the Account Number :10001

Employee Details # 2 :
Enter the Employee number:102
Enter the Employee name:FORGE
Enter the Employee designation:Dr
Enter the Basic pay:32000
Enter the Humen Resource Allowance:2000
Enter the Dearness Allowance :300
Enter the Profitablity Fund:500
Enter the Bank Name:CITI
Enter the IFSC:ISFC0004
Enter the Account Number :20001

Employee number:101
Employee name:MASTE
Employee designation:Er
Employee Basic pay:26000
Employee Humen Resource Allowance:1300
Employee Dearness Allowance:1200
Employee Profitablity Fund:500
Employee Net Pay:28000
Employee Bank Name:SBI
Employee IFSC:ISFC001
Employee Account Number:10001

Employee number:102
Employee name:FORGE
Employee designation:Dr
Employee Basic pay:32000
Employee Humen Resource Allowance:2000
Employee Dearness Allowance:300
Employee Profitablity Fund:500
Employee Net Pay:33800
Employee Bank Name:CITI
Employee IFSC:ISFC0004
Employee Account Number:20001

--------------------------------
Process exited after 82.2 seconds with return value 0
Press any key to continue . . .

Comments