C++进阶实例2--员工分组

  1 #include<iostream>
2 #include<map>
3 #include<vector>
4 #include<ctime>
5 using namespace std;
6
7 #define CEHUA 0
8 #define MEISHU 1
9 #define YANFA 2
10
11 // 员工分组
12 //
13 // 案例描述:
14 // 1. 10名员工(ABCDEFGHIJ)
15 // 2. 员工信息:姓名,薪资组成;部门:策划、没熟、研发
16 // 3. 随机给10名员工分配部门和薪资
17 // 4. 通过multimap进行信息的插入,key(部门编号),value(员工)
18 // 5. 分部门显示员工信息
19 //
20 // 解决思路:
21 // 1. 创建10名员工,存入vector
22 // 2. 遍历vector容器,取出每个员工,进行随机分组
23 // 3. 分组后,将员工编号作为key,具体员工为value,存放到multimap容器中
24 // 4. 分部门显示员工信息
25 //
26
27 // 创建员工
28 class Worker
29 {
30 public:
31 string m_Name;
32 int m_Salary;
33 };
34
35 void createWorker(vector<Worker>& v) {
36
37 string nameSeed = "ABCDEFGHIJ";
38 for (int i = 0; i < 10; i++) {
39 Worker worker;
40 worker.m_Name = "员工";
41 worker.m_Name += nameSeed[i];
42
43 worker.m_Salary = rand() % 10000 + 10000; // 10000 ~ 19999;
44
45 v.push_back(worker);
46 }
47
48 }
49
50 // 员工分组
51 void setGroup(vector<Worker>& v, multimap<int, Worker>& m) {
52 for (vector<Worker>::iterator it = v.begin(); it != v.end(); it++) {
53 // 产生随机部门编号
54 int depId = rand() % 3; // 0, 1, 2
55
56 // 将员工插入到分组中
57 // key表示部门编号,value表示具体员工
58 m.insert(make_pair(depId, *it));
59 }
60 }
61
62 // 分组显式
63 void showWorkerByGroup(multimap<int, Worker>&m) {
64
65 cout << "策划部们:" << endl;
66 multimap<int, Worker>::iterator pos = m.find(CEHUA);
67 int count = m.count(CEHUA); // 统计具体人数
68 int index = 0;
69 for (; pos != m.end() && index < count; pos++, index++) {
70 cout << "姓名:" << pos->second.m_Name << " 薪资:" << pos->second.m_Salary << endl;
71 }
72
73 cout << "-----------------------" << endl;
74 cout << "美术部门:" << endl;
75 pos = m.find(MEISHU);
76 count = m.count(MEISHU); // 统计具体人数
77 index = 0;
78 for (; pos != m.end() && index < count; pos++, index++) {
79 cout << "姓名:" << pos->second.m_Name << " 薪资:" << pos->second.m_Salary << endl;
80 }
81
82 cout << "-----------------------" << endl;
83 cout << "研发部门:" << endl;
84 pos = m.find(YANFA);
85 count = m.count(YANFA); // 统计具体人数
86 index = 0;
87 for (; pos != m.end() && index < count; pos++, index++) {
88 cout << "姓名:" << pos->second.m_Name << " 薪资:" << pos->second.m_Salary << endl;
89 }
90 }
91
92 void test01() {
93
94 // 随机数
95 srand((unsigned int)time(NULL));
96
97 // 1.创建员工
98 vector<Worker>vWorker;
99 createWorker(vWorker);
100
101 // 测试员工信息
102 //for (vector<Worker>::iterator it = vWorker.begin(); it != vWorker.end(); it++) {
103 // cout << "姓名:" << it->m_Name << " 工资:" << it->m_Salary << endl;
104 //}
105
106 // 2.员工分组
107 multimap<int, Worker>mWorker;
108 setGroup(vWorker, mWorker);
109
110 // 3.分组显式员工
111 showWorkerByGroup(mWorker);
112 }
113
114 int main() {
115
116 test01();
117
118 system("pause");
119
120 return 0;
121 }

C++进阶实例2--员工分组的更多相关文章

  1. 《Genesis-3D开源游戏引擎-官方录制系列视频教程:进阶实例篇》

    注:本系列教程仅针对引擎编辑器:v1.2.2及以下版本 G3D进阶实例   第四课<2D编辑与脚本的统一入口> 使用G3D完成一个简单的类飞机大战游戏,介绍了G3D2d游戏制作的流程包括: ...

  2. [代码]multimap员工分组案例

    案例要求: //multimap 案例//公司今天招聘了 5 个员工,5 名员工进入公司之后,需要指派员工在那个部门工作//人员信息有: 姓名 年龄 电话 工资等组成//通过 Multimap 进行信 ...

  3. C++ STL 之 multimap案例之员工分组

    #include <iostream> #include <vector> #include <map> #include <string> #incl ...

  4. MySQL进阶5--分组函数 / 分组排序和分组查询 group by(having) /order by

    MySQL进阶--分组排序和分组查询 group by(having) /order by /* 介绍分组函数 功能:用做统计使用,又称为聚合函数或组函数 1.分类: sum, avg 求和 /平均数 ...

  5. 01_dubbo实例_服务分组

    [为什么要服务分组?] 当一个接口有多种实现时,可以用group区分. [ Provider 的配置信息] <?xml version="1.0" encoding=&quo ...

  6. mysql group by 与order by的实例分析(mysql分组统计后最大值)

    CREATE TABLE `test` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) CHARACTER SET latin1 DEFAULT NULL, `c ...

  7. vue进阶 --- 实例演示

    这篇博客将通过一个实例来对vue构建项目的过程有一个了解. 主要用到的知识点如下所示: vue-router 2.0路由配置 router-view 和 router-link的使用 transiti ...

  8. 《SQL 进阶教程》 自连接分组排序:练习题1-2-2

    分组排序 SELECT d1.district, d1. NAME, (SELECT COUNT(d2.price) FROM district_products d2 WHERE d2.price ...

  9. Java JNI 编程进阶 实例+c++数据类型与jni数据类型转换

    原文:http://www.iteye.com/topic/295776 JNI一直以来都很少去关注,但却是我心中的一个结,最近这几天刚好手头有点时间,因此抽空看了一下这方面的东西,整理了一份文档,J ...

随机推荐

  1. 你对 Spring Boot 有什么了解?

    事实上,随着新功能的增加,弹簧变得越来越复杂.如果必须启动新的 spring 项 目,则必须添加构建路径或添加 maven 依赖项,配置应用程序服务器,添加 spring 配置.所以一切都必须从头开始 ...

  2. 在 centos6 安装 MySQL5.7 官方文档

    Adding the MySQL Yum Repository First, add the MySQL Yum repository to your system's repository list ...

  3. 攻防世界NewsCenter

    NewsCenter 打开题目是一个搜索框我们首先尝试一下sql注入 判断了一下是使用''进行包裹的字符型sql注入 然后我们需要判断数据库列数 1' order by 3# 回显正常但by4的时候回 ...

  4. gulp详细基础教程

    一.gulp简介 1.gulp是什么? gulp是前端开发过程中一种基于流的代码构建工具,是自动化项目的构建利器:它不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成: ...

  5. ES6-11学习笔记--数组遍历

    ES5中数组遍历方式: for循环 forEach():没有返回值,只是针对每个元素调用func map():返回新的Array,每个元素为调用func的结果 filter():返回符合func条件的 ...

  6. 各种类型的Dialog

    下面是几种对话框的效果 图一: 图二: 图三: 图四: 图五: 图六: 图七: 图1效果:该效果是当按返回按钮时弹出一个提示,来确保无误操作,采用常见的对话框样式. 代码: 创建对话框方法dialog ...

  7. 创建新的servlet一定要记得修改web..xml文件!!!

    创建新的servlet一定要记得修改web..xml文件!!!

  8. Unknown host mirrors.opencas.cn You may need to adjust the proxy settings in Gradle 报错及解决办法

    亲测Unknown host mirrors.opencas.cn You may need to adjust the proxy settings in Gradle 解决办法 - 程序员大本营 ...

  9. 小程序安卓端播放不了音频解决方法wx.createInnerAudioContext()

    在小程序播放音频时,使用组件wx.createInnerAudioContext(),安卓端无法播放音频. 我的情况:播放服务器上传来的音频,格式为mp3.首先查看你的格式是否符合文档要求 在安卓端进 ...

  10. Spring-AOP底层实现

    1.aop的底层实现:通过spring提供的动态代理技术实现的,在运行期间,spring通过动态代理技术动态的生成代理对象,代理对象方法执行时增强功能的介入,再去调用目标对象的方法,从而完成功能的增强 ...