Declare the class Employee, consisting of data members are emp_number, emp_name, department, salary and net_salary. The member functions are GetEmpDetails() to accept information for an employee, Calculate_DA() to calculate DA=20% of salary and display() to display the information of a employee.
#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
//default constructor
Employee(){
emp_number = "";
emp_name = "";
Department = "";
salary = 0.0;
net_salary = 0.0;
}
void GetEmpDetails ();
double Calculate_DA ();
void display();
private:
string emp_number;
string emp_name;
string Department;
double salary;
double net_salary;
};
void Employee::GetEmpDetails() {
cout << "Enter employee number: ";
cin >> emp_number;
cout << "Enter employee name: ";
cin >> emp_name;
cout << "Enter Department: ";
cin >> Department;
cout << "Enter employee salary: ";
cin >> salary;
cout << "Enter net salary: ";
cin >> net_salary;
cout << endl;
}
void Employee::display() {
cout<< "**************************************" << endl;
cout << "Information of an employee:" << endl;
cout<< "**************************************" << endl;
cout << "Employee number: " << emp_number << endl;
cout << "Employee name: " << emp_name << endl;
cout << "Department: " << Department << endl;
cout << "Employee salary: "<< salary << endl;
cout << "DA: " << Calculate_DA() << endl;
cout << "Employee salary + DA: "<< salary+Calculate_DA() << endl;
cout << "Net salary: " << net_salary << endl<<endl;
}
double Employee::Calculate_DA (){
return salary*20.0/100;
}
int main()
{
Employee Employee_A;
Employee_A.GetEmpDetails();
Employee_A.display();
return 0;
}
Comments
Leave a comment