Answer to Question #256602 in C++ for Agy

Question #256602
Question 6 [15 Marks] Write a C++ programme to create a class by name Employee. The Employee class should have the following data members 1. Employee_Id 2. Employee_Name 3. Position 4. Department 5. Basic_Pay 6. Deductions (Car Loans, Home Loans, and any other type of loans) The Employee class should have the following member functions. Accept()- It is used to get input for all data members. Total_Salary() – calculates the salary includes HRA 25%, DA 12% & Vehicle allowance 15% of Basic_Pay. This Basic_Pay will be varied based on the different positions. Display() - display all the data that has been received as input along with the calculated salary. Salary is calculated by the formula Salary = Basic_Pay + HRA + DA+ vehicle allowance - deductions. Create N number of Employee details with the necessary object for this class to run this program effectively. (Implement the OOPS concepts Polymorphism, inheritance, and Friend function wherever it is necessary)
1
Expert's answer
2021-10-25T14:49:42-0400
#include<iostream>
#include<string>
using namespace std;
class Employee{
private: 
	string Employee_id;
	string Employee_name;
	string Position;
	string Department;
	double Basic_pay;
	double Deductions;
public:


	Employee(){}
	void Accept (){
		cin.ignore();
		cout<<"Enter employee id: ";
		getline(cin,Employee_id);
		cout<<"Enter employee name: ";
		getline(cin,Employee_name);
		cout<<"Enter employee Position: ";
		getline(cin,Position);
		cout<<"Enter employee Department: ";
		getline(cin,Department);
		cout<<"Enter employee Basic_pay: ";
		cin>>Basic_pay;
		cout<<"Enter employee Deductions: ";
		cin>>Deductions;


	}
	double Total_salary(){
		return Basic_pay + Basic_pay * 0.25 + Basic_pay * 0.12 + Basic_pay * 0.15 - Deductions;
	}




	void Display(){
		cout<<"Employee id: "<<Employee_id<<"\n";
		cout<<"Employee name: "<<Employee_name<<"\n";
		cout<<"Employee Position: "<<Position<<"\n";
		cout<<"Employee Department: "<<Department<<"\n";
		cout<<"Employee Basic_pay: "<<Basic_pay<<"\n";
		cout<<"Employee Deductions: "<<Deductions<<"\n";
		cout<<"Employee Salary: "<<Total_salary()<<"\n";
	}
};




int main(){
	int n;
	cout<<"Enter the number of employees: ";
	cin>>n;
	Employee** employees=new Employee*[n];
	for(int i=0; i<n; i++){
		employees[i]=new Employee();
		employees[i]->Accept();
	}
	for(int i=0; i<n; i++){
		employees[i]->Display();
	}


	


	for(int i=0; i<n; i++){
		delete employees[i];
	}
	delete employees;






	cin>>n;


	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