公司今天招聘了10个员工,10名员工进入公司之后,需要指派员工在那个部门工作
员工信息有:姓名 工资组成;部门分为:策划、美术、研发
随机给10名员工分配部门和工资
通过multimap进行信息的插入 key(部门编号)value(员工)
分部门显示员工信息
创建10名员工,放到vector中
遍历vector容器,取出每个员工,进行随机分组
分组后,将员工部门编号作为key,具体员工作为value,放入到multimap容器中
分部门显示员工信息
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- using namespace std;
-
- #define cehua 0
- #define meishu 1
- #define yanfa 2
-
- class Worker
- {
- public:
- string m_Name;//员工姓名
- int m_Salary;//员工工资
- };
-
- void CreateWorker(vector
&v) - {
- string name = "ABCDEFGHIJ";
- for(int i = 0;i<10;i++)
- {
- Worker worker;
- worker.m_Name = "员工";
- worker.m_Name +=name[i];//姓名
- worker.m_Salary = rand() % 10000 + 10000;//10000 ~ 19999
- //将员工放入到容器中
- v.push_back(worker);
- }
- }
-
- void group(vector
&v,multimap<int,Worker>&m) - {
- //遍历员工
- for(vector
::iterator it = v.begin();it != v.end();it++) - {
- //产生随机部门编号
- int n = rand() % 3;
-
- //将编号和员工容器放到m中
- m.insert(make_pair(n,*it));
- }
- }
-
- void show(multimap<int,Worker>&v)
- {
- cout << "策划部门: "<< endl;
-
- multimap<int,Worker>::iterator pos = v.find(cehua);
- int c = v.count(cehua);
- int i = 0;
- for(;pos!= v.end() && i < c;i++,pos++)
- {
- cout << "姓名: "<< pos->second.m_Name<<"工资: "<
second.m_Salary< - }
-
- cout << "-------------------" << endl;
-
-
- cout << "美术部门: "<< endl;
-
- pos = v.find(meishu);
- c = v.count(meishu);
- i = 0;
- for(;pos!= v.end() && i < c;i++,pos++)
- {
- cout << "姓名: "<< pos->second.m_Name<<"工资: "<
second.m_Salary< - }
- cout << "-------------------" << endl;
-
-
- cout << "研发部门: "<< endl;
-
- pos = v.find(yanfa);
- c = v.count(yanfa);
- i = 0;
- for(;pos!= v.end() && i < c;i++,pos++)
- {
- cout << "姓名: "<< pos->second.m_Name<<"工资: "<
second.m_Salary< - }
- }
-
- int main()
- {
- //创建员工
- vector
vworker; - CreateWorker(vworker);
-
- //分组操作
- multimap<int,Worker>m;
- group(vworker,m);
-
- //分组显示员工
- show(m);
-
- return 0;
- }
编译运行

-
相关阅读:
NIO 实现群聊系统
VS错误代码LNK1168 LNK1168 无法打开 D:\ruanjian\visualstudio\test\03struct\x64\De
面试官:今天要不来聊聊Redis基础吧?
(路透社数据集)新闻分类:多分类问题实战
类隔离(自定义类加载器实现)
数环通入选中国信通院《高质量数字化转型技术方案集(2023)》,积极推动企业数字化转型
Glide讲解
通讯录管理系统-C++课程设计
基于微信小程序的宠物交易商城系统设计与实现(源码+lw+部署文档+讲解等)
[C++][算法基础]欧拉函数(线性筛)
-
原文地址:https://blog.csdn.net/2301_77164542/article/details/133241450
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU