标签:
#include<iostream>
//应用
#include <iostream>
#include<iomanip>
#include<fstream>
#include"PQueue.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//定义请求单的记录
enum Staff{Manager,Supervisor,Worker
};//员工类型 Manager 优先级最高
struct JobRequest
{
Staff staffPerson;
int jobid;
int jobTime;
};//工作状态
int operator<(const JobRequest& a,const JobRequest& b){
return a.staffPerson < b.staffPerson;
}
void PrintJobInfo(JobRequest PR){
switch(PR.staffPerson){
case Manager:
cout <<"Manager ";
break;
case Supervisor:
cout<<"Supervisor ";
break;
case Worker:
cout<<"Worker ";
break;
}
cout<<PR.jobid <<" "<<PR.jobTime<<endl;
}
void PrintJobSummary(int jobServicesUse[]){
cout<<"\nTotal Support Usage\n";
cout<<" Maager "<<setw(3)
<<jobServicesUse[0]<<setw(3)<<endl;
cout<<" Supervisor "<<setw(3)<<jobServicesUse[1]<<endl;
cout<<" Worker "<<setw(3)<<jobServicesUse[2]<<endl;
}
int main(int argc, char** argv) {
//处理不超过50个服务请求单
PQueue<JobRequest> jobpool;
//从fin中读入服务请求单
ifstream fin;
//为每类员工服务的时间
int jobServicesUse[3]={0,0,0};
JobRequest PR;
char ch;
//打开输入文件 job.dat 若失败则退出程序
fin.open("job.dat",ios::in);
if(!fin){
cerr<<"cannot open file job.dat"<<endl;
}
//从文件读入每个请求并插入到优先队列jobpool中
//每行开始为表明员工类别的字符
while(fin>>ch){
switch(ch){
case‘M‘: PR.staffPerson = Manager;
break;
case‘S‘: PR.staffPerson = Supervisor;
break;
case‘W‘: PR.staffPerson = Worker;
break;
default: break;
}
//读入PR的jobid 和jobtime
fin>>PR.jobid;
fin>>PR.jobTime;
//将PR插入到优先级队列
cout<<PR.jobid<<"****"<<endl;
jobpool.PQInsert(PR);
}
//从优先级队列中删除服务并输出该服务的信息
cout<<"Category Job ID Job Time"<<endl;
while(!jobpool.PQEmpty()){
PR = jobpool.PQDelete();
PrintJobInfo(PR);
//对每类员工累计服务时间
jobServicesUse[int(PR.staffPerson)]+=PR.jobTime;
}
PrintJobSummary(jobServicesUse);
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/gaoanchen/article/details/48005819