#ifndef WORKER_CLASS
#define WORKER_CLASS
class Worker
{
private:
int id;
string name;
int age;
Gender gender;
double salary;
friend bool comBySalary(const Worker &a,const Worker &b);
public:
Worker(int ID,char*nam,int ag,Gender gen,double sal):
id(ID),name(nam),age(ag),gender(gen),salary(sal)
{}
void print()
{
cout<<id<<"\t"<<name<<"\t"<<age<<"\t";
if(gender==female)
cout<<"female"<<"\t";
else
cout<<"male"<<"\t";
cout<<salary<<"\t";
}
};
#endif WORKER_CLASS
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
enum Gender{female,male};
#include"Worker.h"
bool comBySalary(const Worker &a,const Worker &b)
{
return a.salary<b.salary;
}
void main()
{
Worker s1(200901,"lily",23,female,2008),
s2(200902,"Tom",24,male,2009),
s3(200903,"lucy",25,female,2010);
Worker a[]={s1,s2,s3};
int n=sizeof(a)/sizeof(*a);
Worker *p,*q;
q=min_element(a,a+n,comBySalary);
*q.print();
p=max_element(a,a+n,comBySalary);
*p.print();
}