公司招聘5个员工,需要指派员工在哪个部门
人员信息: 姓名,年龄,电话,工资组成
通过multimap进行员工的信息的插入,保存,显示
部门显示员工的信息,显示全部员工的信息
#include<iostream>
#include<string>
#include<map>
#include<ctime>
#include<vector>
using namespace std;
class worker
{
public:
string name;
int money;
};
void createWorker(vector<worker>&v)
{
string nameSeed = "ABCDE";
for (int i = 0; i < 5; i++)
{
string name = "员工";
name += nameSeed[i];
int money = rand() % 10000 + 10000;
worker w;
w.name = name;
w.money = money;
v.push_back(w);
}
}
void setGroup(vector<worker>&v,multimap<int,worker>&m)
{
for (vector<worker>::iterator it = v.begin(); it != v.end(); it++)
{
//随机产生部门的编号
int departmentID = rand() % 3; //0 ,1 ,2
//将员工分到multimap容器中
m.insert(make_pair(departmentID, *it));
}
}
enum a
{
RENLI,YANFA,MEISHU
};
void showGroup(multimap<int, worker>&m)
{
//人力部门显示
cout<<"人力部门员工如下"<<endl;
multimap<int,worker>::iterator pos= m.find(RENLI);
int index = 0;
int num = m.count(RENLI);
for (; pos != m.end(),index<num; pos++,index++)
{
cout << "姓名:" << pos->second.name << " 工资:" << pos->second.money << endl;
}
cout << "-----------------------------------------------" << endl;
cout << "研发部门员工如下" << endl;
pos = m.find(YANFA);
index = 0;
num = m.count(YANFA);
for (; pos != m.end(), index < num; pos++, index++)
{
cout << "姓名:" << pos->second.name << " 工资:" << pos->second.money << endl;
}
cout << "-----------------------------------------------" << endl;
cout << "美术部门员工如下" << endl;
pos = m.find(MEISHU);
index = 0;
num = m.count(MEISHU);
for (; pos != m.end(), index < num; pos++, index++)
{
cout << "姓名:" << pos->second.name << " 工资:" << pos->second.money << endl;
}
}
int main()
{
srand((unsigned int)time(NULL));
//声明一个
vector<worker>v;
//创建5名员工.
createWorker(v);
//设置分组
//分组的multimap容器
multimap<int, worker>m;
setGroup(v,m);
//分部门显示员工
showGroup(m);
//员工的创建测试.
/*for (vector<worker>::iterator it = v.begin(); it != v.end(); it++)
{
cout << "姓名:" << it->name << " 工资" << it->money << endl;
}*/
system("pause");
return 0;
}