#include<iostream>
using namespace std;
#include<map>
#include<string>
#include<cstdlib>
#include<vector>
class Person
{
public:
Person(string name,int salary)
{
this->m_name = name;
this->m_salary= salary;
}
string m_name;
int m_salary;
};
void makeperson(vector<Person>& p)//创建员工
{
string nameseed = "ABCDEF";
for (int i = 0; i < 6; i++)
{
string name = "职工";
name += nameseed[i];
int salary = rand()%(8000 - 5000 + 1) + 5000;
Person worker(name,salary);
p.push_back(worker);
}
}
void setdep(vector<Person>& p, multimap<int, Person> &m)//分部门
{
for (int i = 0; i < 6; i++)
{
int d = rand() % (3 - 1 + 1) + 1;
m.insert(make_pair(d, p[i]));
}
}
void show(multimap<int, Person>& m)//展示
{
cout << "策划部门:" << endl;
multimap<int,Person>::iterator pos1 = m.find(1);
int num1 = m.count(1);
int index1 = 0;
for (; pos1 != m.end() && index1 < num1; pos1++, index1++)
{
cout << "姓名:" << pos1->second.m_name
<< " 工资:" << pos1->second.m_salary << endl;
}
cout << "美术部门:" << endl;
multimap<int, Person>::iterator pos2 = m.find(2);
int num2 = m.count(2);
int index2 = 0;
for (; pos2 != m.end() && index2 < num2; pos2++, index2++)
{
cout << "姓名:" << pos2->second.m_name
<< " 工资:" << pos2->second.m_salary << endl;
}
cout << "研发部门:" << endl;
multimap<int, Person>::iterator pos3= m.find(3);
int num3 = m.count(3);
int index3 = 0;
for (; pos3 != m.end() && index3 < num3; pos3++, index3++)
{
cout << "姓名:" << pos3->second.m_name
<< " 工资:" << pos3->second.m_salary << endl;
}
}
void test()
{
vector<Person> p;
makeperson(p);
multimap<int, Person> m;
setdep(p, m);
show(m);
}
int main()
{
test();
return 0;
}