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.
input
1001
charlie
dubai
12000
output
1001
charlie
dubai
14400
#include <iostream>
#include <string>
using namespace std;
class Employee
{
public:
void GetEmpDetails(int num, string name, string dep, double sal);
double Calculate_DA();
void display();
private:
int emp_number;
string emp_name;
string department;
double salary;
double net_salary;
};
void Employee::GetEmpDetails(int num, string name, string dep, double sal)
{
emp_name = name;
emp_number = num;
department = dep;
salary = sal;
}
double Employee::Calculate_DA()
{
net_salary = salary * 1.2;
return net_salary;
}
void Employee::display()
{
cout << "Employee number is " << emp_number << endl;
cout << "Employee name is " << emp_name << endl;
cout << "Department is " << department << endl;
cout << "Salary is " << Calculate_DA() << endl;
}
int main()
{
Employee Bill;
int num = 0;
string name;
string dep;
double sal = 0;
cout << "Enter employee details (number name department salary): ";
cin >> num >> name >> dep >> sal;
Bill.GetEmpDetails(num, name, dep, sal);
cout << endl;
Bill.display();
return 0;
}
Comments
Leave a comment