#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <ctime>
using namespace std;
class Staff
{
public:
Staff(char name, int wages, string department)
{
this->name = name;
this->wages = wages;
this->department = department;
}
char name;
int wages;
string department;
};
void insertStaff(vector<Staff> &staffs)
{
char ch = 'A';
srand((unsigned int)time(NULL));
for (int i = 1; i <= 10; i++, ch++)
{
int random = rand() ;
int random2 = rand() % 3;
string department;
switch (random2)
{
case 0:department = "策划"; break;
case 1:department = "美术"; break;
case 2:department = "研发"; break;
}
staffs.push_back(Staff(ch, random, department));
}
}
void printStaff(const vector<Staff> &staffs)
{
for (vector<Staff>::const_iterator it = staffs.begin(); it != staffs.end(); it++)
{
cout << (*it).name << " " << (*it).wages << " " << (*it).department <<endl;
}
}
void insertmultimap(multimap<int, Staff> &staffmap, vector<Staff> &staffs)
{
int department;
for (vector<Staff>::iterator it = staffs.begin(); it != staffs.end(); it++)
{
if ((*it).department == "策划") department = 0;
if ((*it).department == "美术") department = 1;
if ((*it).department == "研发") department = 2;
char name = (*it).name;
string department1 = (*it).department;
int wages = (*it).wages;
staffmap.insert(pair<int, Staff>(department, Staff( (name, wages, department1) ) ) );
}
}
int main(void)
{
vector<Staff> staffs;
insertStaff(staffs);
printStaff(staffs);
multimap<int, Staff> staffmap;
insertmultimap(staffmap, staffs);
system("pause");
return 0;
}