Answer to Question #186333 in C++ for shay

Question #186333


Get TWO (2) employee information from the user including their names, employee IDs (e.g: EM001), and working hours. Assume they are paid RM255 per hour, display the employee’s information with the highest salary. Salary is calculated based on rate per hour multiply by working hours. Using selection.


1
Expert's answer
2021-04-27T14:21:01-0400
#include <string>
#include <iostream>


using namespace std;


class Employee
{
public:
	Employee(string name, string ID, double workingHours);
	double GetPaid() { return workingHours * rate; }
	void Display();
private:
	string name;
	string ID;
	double workingHours;
	const double rate = 255;
};


Employee::Employee(string name, string ID, double workingHours)
{
	this->name = name;
	this->ID = ID;
	this->workingHours = workingHours;
}


void Employee::Display()
{
	cout << name << " " << ID << " working hours is: " << workingHours << " and his salary is: " << GetPaid() << "RM." << endl;
}


int main()
{
	string name, ID;
	double workingHours;
	cout << "Enter first employee name: ";
	cin >> name;
	cout << "Enter first emplyee ID: ";
	cin >> ID;
	cout << "Enter first emplyee working hours: ";
	cin >> workingHours;
	Employee First(name, ID, workingHours);
	cout << "Enter second employee name: ";
	cin >> name;
	cout << "Enter second emplyee ID: ";
	cin >> ID;
	cout << "Enter second emplyee working hours: ";
	cin >> workingHours;
	cout << endl;
	Employee Second(name, ID, workingHours);
	if (First.GetPaid() > Second.GetPaid())
	{
		First.Display();
	}
	else Second.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