Create a class Employees which have a number, rank, and salary. When an employee is first recruited then all these are given values of 0. Upon confirmation, the actual values of these are entered for the employee. At the time of promotion their rank can be incremented by 1 and an employee gets an increment of 25%. Write a C++ class for Employee.
Input Format
enter 1 if the employee is confirmed as well as details of employee also. enter 2 if the rank is upgraded
Constraints
Salary cant be negative
Output Format
display the details and gross salary.
Sample Input 0

Sample Output 0

SOLUTION
include <cmath>
include <cstdio>
include <vector>
include <iostream>
include <algorithm>
using namespace std;
class employee
{
private:
int emp_number;
char emp_name[30];
float emp_basic;
float emp_da;
float emp_it;
float emp_net_sal;
int rank;
public:
void init_employee();
void get_emp_details();
float find_net_salary(float basic, float da, float it);
void show_emp_details();
void increrank();
};
void employee::init_employee()
{
emp_number=0;
emp_basic=0;
emp_da=0;
emp_it=0;
rank=0;
}
void employee::increrank()
{
rank=rank+1;
emp_basic=emp_basic+(emp_basic25)/100;
emp_da=emp_da+(emp_da25)/100;
emp_it=emp_it+(emp_it*25)/100;
}
void employee::get_emp_details()
{
cin>>emp_number;
cin>>emp_name;
cin>>emp_basic;
cin>>emp_da;
cin>>emp_it;
}
float employee::find_net_salary(float basic, float da, float it)
{
return (basic+da)-it;
}
void employee::show_emp_details()
{
cout<<emp_name;
cout<<"\n"<<emp_number;
cout<<"\n"<<emp_basic;
cout<<"\n"<<emp_da;
cout<<"\n"<<emp_it;
cout<<"\n"<<find_net_salary(emp_basic, emp_da, emp_it);
cout<<"\n";
}
int main()
{
employee emp;
int n, r;
emp.init_employee();
cin>>n;
if(n==1)
{
emp.get_emp_details();
emp.show_emp_details();
}
cin>>r;
if(r==2)
{
emp.increrank();
emp.show_emp_details();
}
return 0;
}
Leave a comment