C++ 员工分组

1、案例描述

  • 公司今天招聘了10个员工(ABCDEFGHIJ),10名员工进入公司之后,需要指派员工在那个部分工作
  • 员工信息有:姓名 工资组成;部分分为:策划、美术、研发
  • 随机给10名员工分配部门和工资
  • 通过multimap进行信息的插入,key(部门编号) value(员工)
  • 分部门显示员工信息
class Employee {
public:
	string name;
	string department;
	int salary;
	Employee(string name,int salary) {
		this->name = name;
		this->salary = salary;
	}
};
void test() {
	vector<Employee>v;
	string name_ = "ABCDEFGH";
	for (int i = 0; i < name_.size(); i++) {
		string name = "worker_";
		name += name_[i];
		int salary = rand() % 5000+5000;
		v.push_back(Employee(name=name,salary=salary));
	}
	multimap<int, Employee>m;
	for (vector<Employee>::iterator it = v.begin(); it != v.end(); it++) {
		int departId = rand() % 3;
		m.insert(pair<int,Employee>(departId,*it));
	}
	multimap<int,Employee>::iterator it = m.find(0);
	int index = 0;
	cout << "策划部门" << endl;
	for (; it != m.end() && index < m.count(0); it++, index++) {
		cout << "name " << it->second.name << " 工资 " << it->second.salary << endl;
	}
	multimap<int, Employee>::iterator it1 = m.find(1);
	index = 0;
	cout << "研发部门" << endl;
	for (; it1 != m.end() && index < m.count(1); it1++, index++) {
		cout << "name " << it1->second.name << " 工资 " << it1->second.salary << endl;
	}
	cout << "美术部门" << endl;
	multimap<int, Employee>::iterator it2 = m.find(2);
	index = 0;
	for (; it2 != m.end() && index < m.count(2); it2++, index++) {
		cout << "name " << it2->second.name << " 工资 " << it2->second.salary << endl;
	}
}

你可能感兴趣的:(c++,c++,java,开发语言)