Program to Identify Employee Department using Multiple Inheritance

In this, we are going to see a program to Identify employee department 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, deptid;
    string empname;
    void getdata()
    {
        cout << "Enter Employee ID: ";
        cin >> empid;
        cout << "Enter Employee Name: ";
        cin >> empname;
        cout << "Enter Department ID: ";
        cin >> deptid;
    }
};

class department
{
    public:
    string dept;
    void getdept(int id)
    {
        switch (id)
        {
        case 1:
            dept = "IT";
            break;
        case 2:
            dept = "CS";
            break;
        case 3:
            dept = "MECH";
            break;
        case 4:
            dept = "PR";
            break;
        default:
            dept = "Unknown";
        }
    }
};

class display : public employee, public department
{
    public:
    void print()
    {
        getdept(deptid);
        cout << "Department of the employee: " << dept;
    }
};

void main()
{
    clrscr();
    display e1;
    e1.getdata();
    e1.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, deptid;
    string empname;
    void getdata()
    {
        cout << "Enter Employee ID: ";
        cin >> empid;
        cout << "Enter Employee Name: ";
        cin >> empname;
        cout << "Enter Department ID: ";
        cin >> deptid;
    }
};

class department
{
    public:
    string dept;
    void getdept(int id)
    {
        switch (id)
        {
        case 1:
            dept = "IT";
            break;
        case 2:
            dept = "CS";
            break;
        case 3:
            dept = "MECH";
            break;
        case 4:
            dept = "PR";
            break;
        default:
            dept = "Unknown";
        }
    }
};

class display : public employee, public department
{
    public:
    void print()
    {
        getdept(deptid);
        cout << "Department of the employee: " << dept;
    }
};

int main()
{
    display e1;
    e1.getdata();
    e1.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