员工分组案例

//公司今天招聘了5个员工,5名员工进入公司之后,需要指派员工在那个部门工作 //人员信息有: 姓名 年龄 电话 工资等组成
//通过Multimap进行信息的插入 保存 显示 //分部门显示员工信息 显示全部员工信息

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
#include <vector>
#include <string>
#include <map>
#include <ctime>
enum
{
	CAIWU,RENLI,MEISHU
};
class Worker
{
public:
	string m_name;//姓名
	int m_money;//工资
};
void createWorker(vector<Worker>& w)
{
	string nameSeed("ABCDE");
	for (int i = 0; i < 5; i++)
	{
		Worker worker;
		worker.m_name = "员工";
		worker.m_name += nameSeed[i];
		worker.m_money = rand() % 1000 + 4000;
		w.push_back(worker);
	}
}
void setGroup(vector<Worker>& v, multimap<int, Worker>& m)
{
	for (vector<Worker>::iterator it = v.begin(); it != v.end(); it++)
	{
		//随机产生部门编号
		int id = rand() % 3 + 1;
		//将员工插入到分组的容器中
		m.insert(make_pair(id, *it));
	}
}
void showWorker(multimap<int, Worker>& m)
{
	// 0 A   0  B   1  C   2  D  2 E
	cout << "财务部门人员如下: " << endl;
	multimap<int, Worker>::iterator pos = m.find(CAIWU);
	int count = m.count(CAIWU);
	int index=0;
	for (; pos != m.end(), index < count; pos++, index++)
	{
		cout << " 姓名 " << pos->second.m_name << " 工资 " << pos->second.m_money;
	}

	cout << "美术部门人员如下: " << endl;
	pos = m.find(MEISHU);
	count = m.count(MEISHU);
	index = 0;

	for (; pos != m.end(), index < count; pos++, index++)
	{
		cout << "姓名: " << pos->second.m_name << " 工资: " << pos->second.m_money << endl;
	}
}
int main() {

	//随机数种子
	srand((unsigned int)time(NULL));
	vector<Worker>v; //存放员工的容器
	//员工的创建
	createWorker(v);

	//员工分组
	multimap<int, Worker>m;
	setGroup(v, m);

	//分部门显示员工
	showWorker(m);


	//for (vector<Worker>::iterator it = v.begin(); it != v.end();it++)
	//{
	//	cout << "姓名: " << it->m_Name << " 工资: " << it->m_Money << endl;
	//}


	system("pause");
	return EXIT_SUCCESS;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值