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{
private:
//data members are emp_number, emp_name, department, salary and net_salary.
string emp_number;
string emp_name;
string department;
double salary;
double net_salary;
public:
//The member functions are GetEmpDetails() to accept information for an employee,
void GetEmpDetails(){
//get Emp number from the user
cout<<"Enter Emp number: ";
getline(cin,emp_number);
//get Emp name from the user
cout<<"Enter Emp name: ";
getline(cin,emp_name);
//get Emp Department from the user
cout<<"Enter Department: ";
getline(cin,department);
//get Emp Salary from the user
cout<<"Enter Salary: ";
cin>>salary;
//get Emp Net salary from the user
cout<<"Enter Net salary: ";
cin>>net_salary;
}
//Calculate_DA() to calculate DA=20% of salary
double Calculate_DA(){
return 0.2*this->salary;
}
//display() to display the information of a employee.
void display(){
cout<<"Emp number: "<<this->emp_number<<endl;
cout<<"Emp name: "<<this->emp_name<<endl;
cout<<"Department: "<<this->department<<endl;
cout<<"Salary: $"<<this->salary<<endl;
cout<<"Net salary: $"<<this->net_salary<<endl;
cout<<"DA: $"<<Calculate_DA()<<endl<<endl;
}
};
//The start point of the program
int main (){
//Create Employee object
Employee employee;
//Get emp details
employee.GetEmpDetails();
//display
employee.display();
//delay
system("pause");
return 0;
}
Comments
Leave a comment