Display Employee Record Having Maximum Salary

#include<iostream>
using namespace std;

/*Employee class declaration*/
class Employee {
int id;
char name[30];
float sal;
public:
void input();
void output();
void showMaxSal(Employee&);
float getSal();
};

/************** empfunction.h ***************/
#include"emp.h"

/*Function to get employee information*/
void Employee::input() {
cout << "\nEnter ID : ";
cin >> id;
cout << "Enter Name : ";
cin >> name;
cout << "Enter Salary : ";
cin >> sal;
}
/*Function to print employee information*/
void Employee::output() {
cout << "\nId \t: " << id;
cout << "\nName \t: " << name;
cout << "\nSalary \t: " << sal;
}
/*function to get maximum salary of employees*/
void Employee::showMaxSal(Employee& e){
cout<<"Employee Having maximum salary : "<<endl;
if(sal>e.sal)
output();
else if(e.sal>sal)
e.output();
else{
output();
e.output();
}
}
/*Function to return salary of employee*/
float Employee::getSal(){
return sal;
}


/************ Main ************/
#include"empfunction.h"
#define SIZE 3

int main(int argc, char const *argv[])
{
/*Creating array of employee objects*/
Employee emp[SIZE],empMaxSal;

/*accepting employee data */
for (int i = 0; i < SIZE; ++i)
{
emp[i].input();
}

/*printing employee data*/
// cout<<"\nEmployee Details of "<<SIZE<<endl;

for (int i = 0; i < SIZE-1; ++i)
{
/*assign first obj as maximum salary object*/
empMaxSal=emp[i];
for (int j = i+1; j < SIZE ; ++j)
{
if(emp[i].getSal() < emp[j].getSal())
empMaxSal=emp[j];
}
}
cout<<"Details of employee with Maximum Salary : "<< endl;
empMaxSal.output();
return 0;
}


/*Cant get desired output, it is showing last entered record*/
Duplicated post. http://www.cplusplus.com/forum/general/176495/

Please use the code tags for your code. HINT: Edit your post, highlight your whole code, then select the <> icon on your right side of the post.
Topic archived. No new replies allowed.