项目要求:
1、员工类中包含以下元素:
员工编号
部门编号
姓名
年龄
工资
2、按需求显示:
(1)按部门升序显示,在部门中按员工编号显示;
(2)按工资从高到低显示,工资水平一样的按照部门升序显示,部门里按员工编号升序;
3、查找:
按员工编号查找
4、删除:
按员工编号删除;
删除 工资 低于 1000元的员工;
删除 某个 部门的所有员工
程序示例:
#include <iostream>
#include <algorithm>
#include <list>
using namespace std;
class Emp{
private:
int empno;
int deptno;
string name;
int age;
double salary;
public:
int getEmpNo()const{
return empno;
}
int getDeptNo()const{
return deptno;
}
string getName()const{
return name;
}
int getAge()const{
return age;
}
double getSalary()const{
return salary;
}
Emp(int empno=0,int deptno=0,string name="",int age=0,double salary=0):
empno(empno),deptno(deptno),name(name),age(age),salary(salary){}
bool operator==(const Emp& e)const{
return empno == e.empno;
}
int operator<(const Emp& e)const{
return empno < e.empno;
}
friend ostream& operator<<(ostream& os,const Emp& e){
return os << e.empno << ":" << e.deptno << ":" << e.name << ":" << e.age << ":" << e.salary;
}
friend istream& operator>>(istream& is,Emp& e){
return is>>e.empno>>e.deptno>>e.name>>e.age>>e.salary;
}
};
class Comp1{
public:
int operator()(const Emp& e1,const Emp& e2){
if(e1.getDeptNo() == e2.getDeptNo()){
return e1.getEmpNo() < e2.getEmpNo();
}
return e1.getDeptNo() < e2.getDeptNo();
}
};
class Comp2{
public:
int operator()(const Emp& e1,const Emp& e2){
if(e1.getSalary() == e2.getSalary()){
Comp1 c;
return c(e1,e2);
}
return e1.getSalary() > e2.getSalary();
}
};
class Cond1{
public:
bool operator()(const Emp& e){
return e.getSalary() < 1000;
}
};
class Cond2{
public:
Cond2(int deptno):deptno(deptno){}
bool operator()(const Emp& e){
return e.getDeptNo == deptno;
}
private:
int deptno;
};