Getting Employee Salary Detail using Single Inheritance in C++ || Single Inheritance || C++

In this, we are going to see a program to Identify Employee Salary 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 EmpDetails
{
    public:
    int empId;
    char empName[50];
    double basic;
    EmpDetails()
    {
        empId = 0;
        //strcpy(empName,"NULL");
        basic = 0.0;
    }
    void get()
    {
        cout << "Enter Employee ID: ";
        cin >> empId;
        cout << "Enter Employee Name: ";
        cin >> empName;
        cout << "Enter basic salary of Employee: ";
        cin >> basic;
    }
};

class Calc : public EmpDetails
{
public:
    int IT;
    double DA()
    {
        return 0.7 * basic;
    }
    double HRA()
    {
        return 0.3 * basic;
    }
    double PF()
    {
        return 0.1 * basic;
    }
    double GrossSal()
    {
        return basic + DA() + HRA();
    }
    double NetSal()
    {
        IT = 100;
        return basic - PF() - IT;
    }
};

void main()
{
    clrscr();
    Calc emp1;
    cout << "Enter details of the Employee: \n";
    emp1.get();
    cout << "\n\nEmployee Details: \n";
    cout << "Emp ID: " << emp1.empId;
    cout << "\nEmp Name: " << emp1.empName;
    cout << "\nEmp Basic Salary = Rs. " << emp1.basic;
    cout << "\nGross Salary = Rs. " << emp1.GrossSal();
    cout << "\nNet Salary = Rs. " << emp1.NetSal();
    getch();
}

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

 

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

#include <iostream>
#include <string>
using namespace std;

class EmpDetails
{
    public:
    int empId;
    string empName;
    double basic;
    EmpDetails()
    {
        empId = 0;
        //strcpy(empName,"NULL");
        basic = 0.0;
    }
    void get()
    {
        cout << "Enter Employee ID: ";
        cin >> empId;
        cout << "Enter Employee Name: ";
        cin >> empName;
        cout << "Enter basic salary of Employee: ";
        cin >> basic;
    }
};

class Calc : public EmpDetails
{
public:
    int IT = 100;
    double DA()
    {
        return 0.7 * basic;
    }
    double HRA()
    {
        return 0.3 * basic;
    }
    double PF()
    {
        return 0.1 * basic;
    }
    double GrossSal()
    {
        return basic + DA() + HRA();
    }
    double NetSal()
    {
        return basic - PF() - IT;
    }
};

int main()
{
    Calc emp1;
    cout << "Enter details of the Employee: \n";
    emp1.get();
    cout << "\n\nEmployee Details: \n";
    cout << "Emp ID: " << emp1.empId;
    cout << "\nEmp Name: " << emp1.empName;
    cout << "\nEmp Basic Salary = Rs. " << emp1.basic;
    cout << "\nGross Salary = Rs. " << emp1.GrossSal();
    cout << "\nNet Salary = Rs. " << emp1.NetSal();
    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