Answer to Question #180651 in C++ for Ishan

Question #180651


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. 


1
Expert's answer
2021-04-12T17:55:30-0400
#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;
}

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