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.
#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;
}
Comments
Leave a comment