In this, we are going to see a program to Identify employee's salary using Multilevel 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;
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;
}
long long int GrossSal()
{
return basic + DA() + HRA();
}
double NetSal()
{
return basic - PF() - IT;
}
};
class Show : public Calc
{
public:
void show()
{
cout << "\n\nEmployee Details- \n";
cout << "Emp ID: " << empId;
cout << "\nEmployee Name: "<< empName;
cout << "\nEmployee Basic Salary = Rs. " << basic;
cout << "\nGross Salary = Rs. " << GrossSal();
cout << "\nNet Salary = Rs. " << NetSal();
}
};
void main()
{
clrscr()
Show emp;
cout << "Enter details of the employee: \n";
emp.get();
emp.show();
getch();
}
//...........Coded by Sahil Shaikh
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class EmpDetails
{
public:
int empId;
string empName;
double basic;
EmpDetails()
{
empId = 0;
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;
}
long long int GrossSal()
{
return basic + DA() + HRA();
}
double NetSal()
{
return basic - PF() - IT;
}
};
class Show : public Calc
{
public:
void show()
{
cout << "\n\nEmployee Details- \n";
cout << "Emp ID: " << empId;
cout << "\nEmployee Name: " << empName;
cout << "\nEmployee Basic Salary = Rs. " << basic;
cout << "\nGross Salary = Rs. " << GrossSal();
cout << "\nNet Salary = Rs. " << NetSal();
}
};
int main()
{
Show emp;
cout << "Enter details of the employee: \n";
emp.get();
emp.show();
return 0;
}
//...........Coded by Sahil Shaikh
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP