Employee detail program using Single Inheritance in C++ || Single Inheritance || C++

In this, we are going to see a program to Identify Employee Department using Single 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, dept;
    void getDetails()
    {
        cout << "Enter Employee ID: ";
        cin >> empId;
        cout << "Enter Employee Name: ";
        cin >> empName;
        cout << "Enter Department ID: ";
        cin >> deptId;
    }
};

class Department : public Employee
{
public:
    void GetDept()
    {
        switch (deptId)
        {
        case 201:
            dept = "IT";
            break;
        case 202:
            dept = "CS";
            break;
        case 203:
            dept = "MECH";
            break;
        case 204:
            dept = "PR";
            break;
        default:
            dept = "Unknown";
        }
    }
};

void main()
{
    clrscr();
    Department obj;
    obj.getDetails();
    obj.GetDept();
    cout << "Department of the employee: " << obj.dept;
    getch();
}

//...........Coded by Shreya Idate

 

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

#include <iostream>
using namespace std;

class Employee
{
public:
    int empId, deptId;
    string empName, dept;
    void getDetails()
    {
        cout << "Enter Employee ID: ";
        cin >> empId;
        cout << "Enter Employee Name: ";
        cin >> empName;
        cout << "Enter Department ID: ";
        cin >> deptId;
    }
};

class Department : public Employee
{
public:
    void GetDept()
    {
        switch (deptId)
        {
        case 201:
            dept = "IT";
            break;
        case 202:
            dept = "CS";
            break;
        case 203:
            dept = "MECH";
            break;
        case 204:
            dept = "PR";
            break;
        default:
            dept = "Unknown";
        }
    }
};

int main()
{
    Department obj;
    obj.getDetails();
    obj.GetDept();
    cout << "Department of the employee: " << obj.dept;
    return 0;
}

//...........Coded by Shreya Idate
    

#ENJOY CODING

Post a Comment

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

Previous Post Next Post