Create a class Employee with following data members, name, id, and salary as private data member. Create array of objects for four employees, compare their salary using operator overloading, and display the records of the student who is getting less salary.
#include <string>
#include <iostream>
using namespace std;
class Employee
{
public:
Employee() {}
Employee(string name, int id, double salary);
bool operator < (const Employee& RHS);
void Display();
private:
string name;
int id;
double salary;
};
Employee::Employee(string name_, int id_, double salary_) : name(name_), id(id_), salary(salary_)
{}
bool Employee::operator<(const Employee& RHS)
{
return salary < RHS.salary;
}
void Employee::Display()
{
cout << id << " " << name << " $" << salary << endl;
}
int main()
{
Employee Team[4];
Team[0] = Employee("Bill", 1, 12500);
Team[1] = Employee("Brian", 2, 15500);
Team[2] = Employee("Kate", 3, 2500);
Team[3] = Employee("Liza", 4, 7500);
Employee min(Team[0]);
for (int i = 0; i < 4; i++)
{
if (Team[i] < min)
min = Team[i];
}
min.Display();
return 0;
}
Comments
Leave a comment