Answer to Question #174163 in C++ for P. Gokul

Question #174163

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.


1
Expert's answer
2021-03-24T01:24:55-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS