```
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#include<cstdlib>
#include<ctime>
using namespace std; #define SALE_DEPATMENT 1//销售部门
#define DEVELOP_DEPATMENT 2//研发部门
#define FINACIAL_DEPATMENT 3//财务部门 /*multimap案例
公司今天招聘了5个员工,5名员工进入公司之后,需要指派员工在那个部门工作
人员信息有:姓名 年龄 电话 工资等组成
通过multimap 进行信息的插入 保存 显示
分部门显示员工信息 显示全部员工信息*/ class Worker{
public:
string mName;
string mTele;
int mAge;
int mSalary;
}; void Creat_Worker(vector<Worker>& vWorker){
string seedName="ABCDE";
for( int i=; i<; i++ ){
Worker worker;
worker.mName="员工";
worker.mName+=seedName[i]; worker.mAge=rand()%+;
worker.mTele="010-8888888";
worker.mSalary=rand()%+;
//保存员工信息
vWorker.push_back(worker); }
} //员工分组
void WorkerByGroup(vector<Worker>& vWorker,multimap<int,Worker>& WorkerGroup){
//把员工随机分配到不同的部门
srand(time(NULL));
for(vector<Worker>::iterator it=vWorker.begin(); it!=vWorker.end(); it++ ){
int departID=rand()%+;
switch(departID){
case SALE_DEPATMENT:
WorkerGroup.insert(make_pair(SALE_DEPATMENT,*it));
break;
case DEVELOP_DEPATMENT:
WorkerGroup.insert(make_pair(DEVELOP_DEPATMENT,*it));
break;
case FINACIAL_DEPATMENT:
WorkerGroup.insert(make_pair(FINACIAL_DEPATMENT,*it));
break;
default:
break;
}
} } void ShowGroupWorkers(multimap<int,Worker>& WorkerGroup,int departID){
multimap<int,Worker>::iterator it=WorkerGroup.find(departID);
int DepartCount=WorkerGroup.count(departID);
int num=;
for( ;num<DepartCount&&it!=WorkerGroup.end(); it++,num++ ){
cout<<"姓名:"<<it->second.mName<<" 年龄:"<<it->second.mAge<<" 电话:"
<<it->second.mTele<<" 工资:"<<it->second.mSalary<<endl;
}
} //打印每一部门的员工信息
void PrintWorkerByGroup(multimap<int,Worker>& WorkerGroup){
//打印销售部员工信息
cout<<"销售部门"<<endl;
ShowGroupWorkers(WorkerGroup,SALE_DEPATMENT);
//打印研发部员工信息
cout<<"研发部门"<<endl;
ShowGroupWorkers(WorkerGroup,DEVELOP_DEPATMENT);
//打印财务部员工信息
cout<<"财务部门"<<endl;
ShowGroupWorkers(WorkerGroup,FINACIAL_DEPATMENT); } int main(){
//存放新员工的信息
vector<Worker> vWorker;
//multimap保存分组信息
multimap<int,Worker> WorkerGroup;
//创建员工
Creat_Worker(vWorker);
//员工分组
WorkerByGroup(vWorker,WorkerGroup);
//打印每一部门的员工信息
PrintWorkerByGroup(WorkerGroup); return ;
} ```