Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
984 B
0
Indexable
Never
#include<iostream>
using namespace std;

class Employee
{
	private:
		
		
	public:
		string name;
		double salary;
		void getdata()
		{
			cout<<"Enter the name of employee";
			cin>>name;
			cout<<"Enter the salary of employee";
			cin>>salary;
		}
		bool operator >(Employee e)
		{
			if(e.salary>e[i].salary)
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		
};

int main()
{
	Employee e[5];
	for(int i=0;i<5;i++)
	{
		cout<<"For employee : "<<i+1<<endl;
		e[i].getdata();
	}
	
	//Sorting 
	for(int i=0;i<5;i++)
	{
		for(int j=i+1;j<5;j++)
		{
			if(e[i].salary>e[j].salary)
			{
		         double temp=e[i].salary;
				 e[i].salary=e[j].salary;
				 e[j].salary=temp;
				 
				 string temps;
				 temps=e[i].name;
				 e[i].name=e[j].name;
				 e[j].name=temps;
			}
		}
	}
	//Printing
	cout<<"Ascending order according to salary::"<<endl;
	for(int i=0;i<5;i++)
	{
		cout<<e[i].name<<endl;
		
	}
	
}