员工信息情况分部门展示

2019/03/29
今天第一天写自己的第一个案例,也希望能让自己的程序员之路可以走的更远
/* 员工分部门显示情况 */
话不多说,代码跑起来结果如图所示,因为加了随机数种子,所以每次情况都会不一样的,具体还有很多种情况,不以此图为唯一标准

#include<iostream>
using namespace std
//使用vector容器
#include<vector>
#include<string>
#include<ctime>
enmu{ renli , jishu, meishu };   //0   1    2

class  Worker{
public:
	Worker(string name,int money){
		this->m_name=name;
		this->money=money;
}
	string m_name;
	int m_money;
};
//建立员工
void setPerson(vector<Worker>&v){
		string nameID="ABCDE";
		for(int i=0;i<5;i++){
					string name="员工";
					name+=nameID[ i ] ;
					int money=rand()%10000+10000;     //工资范围在10000~19999
					Worker P;
					P.m_name=name;
					P.m_money=money;
					v.push_back(P);
		}
}
//设置随机部门
void setGroup(vector<Worker>v,multimap<int,Worker>p){
		for(vector<Worker>::iterator it=v.begin();it!=v.end();it++){
				int department = rand()%3;   //0  1  2
				p.insert(make_pair(department,*it));
		}
}
//展示各部门情况
void showGroup(multimap<int,Worker>&p){
		cout << "人力部门如下 " << endl;
		//利用find()查找数据    返回的是一个迭代器
		multimap<int,Worker>::iterator pos = p.find(renli);
		int index=0;
		int num=count(renli);   //统计renli 数目
		for(;pos!=p.end(),index<num;pos++,index++){
				cout<< "姓名是:" << pos.second->m_name << "工资是: " << pos.second->m_money;
		}
		cout<<"----------------------------------" << endl;
		cout << "技术部门如下 " << endl;
		//利用find()查找数据    返回的是一个迭代器
		multimap<int,Worker>::iterator pos = p.find(jishu);
		int index=0;
		int num=count(jishu);   //统计jishu`在这里插入代码片` 数目
		for(;pos!=p.end(),index<num;pos++,index++){
				cout<< "姓名是:" << pos.second->m_name << "工资是: " << pos.second->m_money;
		}
		cout<<"----------------------------------" << endl;
		cout << "美术部门如下 " << endl;
		//利用find()查找数据    返回的是一个迭代器
		multimap<int,Worker>::iterator pos = p.find(meishu);
		int index=0;
		int num=count(meishu);   //统计meishu 数目
		for(;pos!=p.end(),index<num;pos++,index++){
				cout<< "姓名是:" << pos.second->m_name << "工资是: " << pos.second->m_money;
		}
}
int main(){
	//用容器存放5个员工
	vector<Worker>v;
	//建立员工
	setPerson( v );
	//建立部门
	multimap< int , Worekr > p;
	setGroup( v , p );
	//展示部门
	showGroup(p);
	system( "pause" );
	return EXIT_SUCCESS;
}

猜你喜欢

转载自blog.csdn.net/qq_42806753/article/details/88893684