Answer to Question #254527 in C++ for Kamo

Question #254527
Write a C++ program to create a class by a name Employee. The Employee class must have the following data members. Employee-id Employee-name Position Department Basic-pay Deductions(car loans, home loans, and any other type of loans ) The Employee class must 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% and vehicle allowance 15% of basic-pay. This basic-pay will be varied based on different positions. Display ()- Display all data that has been received as an input along with a calculated salary. Salary is calculated by the formula Salary = Basic-pay + HRA + DA + Vehicle allowance - Deductions. Create N number of Employee details with necessary object for this class to run this program efficiently.( Implement the OOPS concept Polymorphism , inharitance, and friend function where it is necessary).
1
Expert's answer
2021-10-21T14:24:29-0400
#include<iostream>
using namespace std;
class Employee{
	private: 
	string Employee_id, Employee_name, Position,Department;
  double Basic_pay, Deductions;
  public:
  	void Accept (){
  		cout<<"Enter employee id\n";
  		cin>>Employee_id;
  		cout<<"Enter employee name\n";
  		cin>>Employee_name;
  		cout<<"Enter employee Position\n";
  		cin>>Position;
  		cout<<"Enter employee Department\n";
  		cin>>Department;
  		cout<<"Enter employee Basic_pay\n";
  		cin>>Basic_pay;
  		cout<<"Enter employee Deductions\n";
  		cin>>Deductions;
  		
	  }
double Total_salary(){
	double Salary = Basic_pay + Basic_pay * 0.25 + Basic_pay * 0.12 + Basic_pay * 0.15 - Deductions;
	return Salary;
}


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


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

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