Program to Identify Employee's Salary using Multiple Inheritance

In this, we are going to see a program to Identify employee's salary using Multiple Inheritance in C++ Programming Language. 


The Code given below can be used in TURBO C++ Compilers: -

#include<iostream.h>
#include<conio.h>

class employee
{
    public:
    int empid;
    char empname[50];
    double basic;
    void getdata()
    {
        cout << "Enter details of the Employee:" << endl;
        cout << "Enter Employee ID: ";
        cin >> empid;
        cout << "Enter Employee Name: ";
        cin >> empname;
        cout << "Enter basic salary of Employee: ";
        cin >> basic;
    }
};

class calculate
{
    public:
    int it = 100;
    double da, hra, pf, gs, ns;
    void calc(int b)
    {
        da = 0.7 * b;
        hra = 0.3 * b;
        pf = 0.1 * b;
        gs = b + da + hra;
        ns = b - pf - it;
    }
};

class display : public employee, public calculate
{
    public:
    void print()
    {
        cout << "\nEmployee Details:";
        cout << "Employee ID: " << empid << endl;
        cout << "Employee Name: " << empname << endl;
        cout << "Basic Salary: Rs." << basic << endl;
        calc(basic);
        cout << "Gross Salary: Rs." << gs << endl;
        cout << "Net Salary: Rs." << ns << endl;
    }
};

void main()
{
    clrscr();
    display emp1;
    emp1.getdata();
    emp1.print();
    getch();
}

//...........Coded by Ananya Vidyadharan
 

The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

class employee
{
    public:
    int empid;
    string empname;
    double basic;
    void getdata()
    {
        cout << "Enter details of the Employee:" << endl;
        cout << "Enter Employee ID: ";
        cin >> empid;
        cout << "Enter Employee Name: ";
        cin >> empname;
        cout << "Enter basic salary of Employee: ";
        cin >> basic;
    }
};

class calculate
{
    public:
    int it = 100;
    double da, hra, pf, gs, ns;
    void calc(int b)
    {
        da = 0.7 * b;
        hra = 0.3 * b;
        pf = 0.1 * b;
        gs = b + da + hra;
        ns = b - pf - it;
    }
};

class display : public employee, public calculate
{
    public:
    void print()
    {
        cout << "\nEmployee Details:";
        cout << "Employee ID: " << empid << endl;
        cout << "Employee Name: " << empname << endl;
        cout << "Basic Salary: Rs." << basic << endl;
        calc(basic);
        cout << "Gross Salary: Rs." << gs << endl;
        cout << "Net Salary: Rs." << ns << endl;
    }
};

int main()
{
    display emp1;
    emp1.getdata();
    emp1.print();
    return 0;
}

//...........Coded by Ananya Vidyadharan
    

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post