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 <iomanip>
#include <string>
using namespace std;
class Employee {
int emp_number;
string emp_name;
string department;
double salary;
double net_salary;
public:
Employee(int num, string name, string dep, double salary);
void GetEmpDerails(int& num, string& name, string& department, double& salary, double& net_salary);
void Calculate_DA();
void display();
};
Employee::Employee(int num, string name, string dep, double salary) :
emp_number(num), emp_name(name), department(dep), salary(salary), net_salary(salary)
{}
void Employee::GetEmpDerails(int& num, string& name, string& department, double& salary, double& net_salary)
{
num = emp_number;
name = emp_name;
department = this->department;
salary = this->salary;
net_salary = this->net_salary;
}
void Employee::Calculate_DA() {
net_salary = 1.2*salary;
}
void Employee::display() {
cout << "Employee number:" << emp_number << endl;
cout << "Employee name: " << emp_name << endl;
cout << "Department: " << department << endl;
cout << "Salary: $" << fixed << setprecision(2) << salary << endl;
cout << "Net salary: $" << net_salary << endl;
}
int main() {
Employee smith(0, "Smith", "security", 100000 );
Employee bond(7, "James Bond", "Intelligence", 200000);
bond.Calculate_DA();
cout << "Our staff:" << endl;
smith.display();
cout << endl;
bond.display();
cout << endl;
}
Comments
Leave a comment