20240511,谓词,内建函数对象

拜托铠甲勇士真的帅好不好!!!

 STL案例2-员工分组

10个员工,指派部门,员工信息(姓名,工资组成,部门:策划,美术,研发),随机分配部门和公司,MULTIMAP插入信息,KEY部门编号,VAL员工,分部门显示员工信息

#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<ctime>
using namespace std;
#define CEHUA 0
#define SHEJI 1
#define KAFA 2

class Worker {
public:
	Worker(string name, int salary) {
		this->_name = name;
		this->_sal = salary;
	}
public:
	string _name;
	int _sal;
};
void creatww(vector<Worker>& w) {
	srand((unsigned int)time(NULL));
	string nameseed = "ABCDEFGHIJ";
	for (int i = 0; i < 10; i++) {
		string name = "员工-";
		name += nameseed[i];
		int sal=rand() % 6001 + 7000;
		Worker p(name, sal);
		w.push_back(p);
	}
}
void setgroup(vector<Worker> w,multimap<int, Worker> &mw) {
	for (vector<Worker>::iterator it = w.begin(); it != w.end(); it++) {
		//产生随机部门编号
		int depid = rand() % 3;
		mw.insert(make_pair(depid, *it));
	}
}
void showgroup(multimap<int,Worker>&mw) {
	cout << endl;
	cout << "group CEHUA:\t" << endl;
	multimap<int, Worker>::iterator pos = mw.find(CEHUA);
	int count = mw.count(CEHUA);//统计具体人数
	int index = 0;
	for (; pos != mw.end() && index < count; pos++, index++) {//pos->first!=CEHUA不对脑子清醒了再试
		cout << pos->second._name << " " << pos->second._sal << endl;
	}
	cout << endl;
	cout << "group SHEJI:\t" << endl;
	pos = mw.find(SHEJI);
	count = mw.count(SHEJI);//统计具体人数
	index = 0;
	for (; pos != mw.end() && index < count; pos++, index++) {
		cout << pos->second._name << " " << pos->second._sal << endl;
	}
	cout << endl;
	cout << "group KAFA:\t" << pos->first << endl;
	pos = mw.find(KAFA);
	count = mw.count(KAFA);//统计具体人数
	index = 0;
	for (; pos != mw.end() && index < count; pos++, index++) {
		cout << pos->second._name << " " << pos->second._sal << endl;
	}
}
void tst01() {
	vector<Worker>w;
	creatww(w);
	for (vector<Worker>::iterator it = w.begin(); it != w.end(); it++) {
		cout << it->_name << " " << it->_sal << endl;
	}
	cout << endl;
	multimap<int, Worker>mw;
	setgroup(w,mw);
	showgroup(mw);
}
int main() {
	tst01();
	system("pause");
	return 0;
}

相关推荐

  1. C++算法——函数对象\谓词\置仿函数

    2024-05-11 23:30:11       35 阅读
  2. 函数对象

    2024-05-11 23:30:11       108 阅读
  3. STL——函数对象谓词

    2024-05-11 23:30:11       34 阅读
  4. 20240311

    2024-05-11 23:30:11       38 阅读
  5. STL仿函数

    2024-05-11 23:30:11       28 阅读
  6. c++ 函数对象的释放

    2024-05-11 23:30:11       33 阅读
  7. Hive、MySQL、Oracle函数对照表

    2024-05-11 23:30:11       59 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-11 23:30:11       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-11 23:30:11       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-11 23:30:11       87 阅读
  4. Python语言-面向对象

    2024-05-11 23:30:11       96 阅读

热门阅读

  1. Qt 简单使用串口

    2024-05-11 23:30:11       35 阅读
  2. 面试题:Go协程泄漏原因及解决方法

    2024-05-11 23:30:11       33 阅读
  3. LeetCode 212.单词搜索II

    2024-05-11 23:30:11       30 阅读
  4. 采购管理软件:采购自动化提高效率的5种方式

    2024-05-11 23:30:11       33 阅读
  5. QT_BEGIN_NAMESPACE

    2024-05-11 23:30:11       33 阅读