Answer to Question #173428 in C++ for VARUN

Question #173428

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-19T13:08:56-0400
#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;
}

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