公司今天招聘了10个员工(ABCDEFGHIJ),10名员工进入公司之后需要指派员工在那个部门工作
- 员工信息有:姓名工资组成,部门分为策划、美术、研发
- 随机给10名员工分配部门和工资
- 通过multimap进行信息的插入 key(部i编号) value(员工)
- 分部门显示员工信息
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <ctime>
using namespace std;
enum BM
{
CEHUA=1,
MEISHU,
YANFA
};
/*公司今天招聘了10个员工(ABCDEFGHIJ)10名员工进入公司之后
需要指派员工在那个部门工作员工信息有:姓名工资组成,部门分为策划、美术、研发
随机给10名员工分配部门和工资
通过multimap进行信息的插入 key(部i编号) value(员工)
分部门显示员工信息*/
class Worker
{
public:
string M_Name;
int M_Salary;
};
void createWorker(vector<Worker> &v)
{
string NameNeed = "ABCDEFGHIJ";
for (int i = 0; i < NameNeed.size(); i++)
{
Worker w;
w.M_Name = "员工";
w.M_Name += NameNeed[i];
w.M_Salary = rand() % 10001 + 10000;
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 dep = rand() % 3 + 1;//随机部门
m.insert(make_pair(dep, *it));//插入到分组中
}
}
void printmultimap(multimap<int, Worker>::iterator pos, multimap<int, Worker>::iterator end, int count)
{
switch (pos->first)
{
case CEHUA:
cout << "策划部门:" << endl;
break;
case MEISHU:
cout << "美术部门:" << endl;
break;
case YANFA:
cout << "研发部门:" << endl;
break;
default:
break;
}
for(int i = 0; pos != end&&i<count; pos++, i++)
{
cout << "\t姓名:" << pos->second.M_Name <<
" 工资:" << pos->second.M_Salary << endl;
}
}
void showWorkerBysetGroup(multimap<int, Worker> &m)
{
//打印策划部门人员
printmultimap(m.find(CEHUA),m.end(),m.count(CEHUA));
//打印美术部门人员
printmultimap(m.find(MEISHU), m.end(), m.count(MEISHU));
//打印研发部门人员
printmultimap(m.find(YANFA), m.end(), m.count(YANFA));
}
int main()
{
srand((unsigned int)time(NULL));
//1.创建10个员工
vector<Worker>vWorker;
createWorker(vWorker);
////打印测试
//for (auto it = vWorker.begin(); it != vWorker.end(); it++)
// cout << "姓名:" << it->M_Name << " 工资:" << it->M_Salary << endl;
//2.创建部门
multimap<int, Worker> mDep;
//3.员工部门分配
setGroup(vWorker, mDep);
//for (auto it = mDep.begin(); it != mDep.end(); it++)
// cout <<"Key="<<it->first<< "姓名:" << it->second.M_Name << " 工资:" << it->second.M_Salary << endl;
//4.分部门显示员工信息
showWorkerBysetGroup(mDep);
system("pause");
return 0;
}