实验一动态高优先权优先实验内容:模拟实现动态高优先权优先(若数值越大优先权越高,每运行一个时间单位优先权-n,若数值越小优先权越高,没运行一个时间单位优先权+n),具体如下:设置进程体:进程名,进程的到达时间,服务时间,初始优先权,进程状态(W——等待,R——运行,F——完成),进程间的链接指针进程初始化:由用户输入进程名、服务时间、初始优先权进行初始化,同时,初始化进程的状态为W。显示函数:在进程调度前、调度中和调度后进行显示。排序函数:对就绪状态的进程按照优先权排序。优先权相同时进入就绪队列时间早的进程在前。注意考虑到达时间调度函数:每次从就绪队列队首调度优先权最高的进程执行,状态变化。并在执行一个时间单位后优先权变化,服务时间变化,状态变化。当服务时间为0时,状态变为F。删除函数:撤销状态为F的进行。实验要求:1、测试数据可以随即输入或从文件中读入。2、必须要考虑到进程的到达时间3、最终能够计算每一个进程的周转时间的带权周转时间。实验代码:#includeiostream#includestring#includetime.husingnamespacestd;intn;classPCB{public:intpri;intruntime;intpieceOftime;stringprocname;stringstate;intneedOftime;intCounter;PCB*next;};PCB*run=NULL;PCB*ready=NULL;PCB*finish=NULL;PCB*tial=ready;voidDtime(intt);voidPrinft(inta){if(a==1){cout\n进程名\t到达时间\t服务时间\t优先权\t进程状态endl;}}voidPrinft(intb,PCB*p){if(b==1){coutp-procname\tp-needOftime\t\tp-runtime\t\tp-pri\tp-stateendl;}}voiddisplay(intc){PCB*p;if(run!=NULL)Prinft(c,run);p=ready;while(p!=NULL){Prinft(c,p);p=p-next;}p=finish;while(p!=NULL){Prinft(c,p);p=p-next;}}voidinsert(PCB*p){PCB*S1,*S2;if(ready==NULL){p-next=NULL;ready=p;}else{S1=ready;S2=S1;while(S1!=NULL){if(S1-pri=p-pri){S2=S1;S1=S1-next;}elsebreak;}if(S2-pri=p-pri){S2-next=p;p-next=S1;}else{p-next=ready;ready=p;}}}boolCTProcessOfPri(){PCB*Node;cout输入创建进程的数目:endl;cinn;for(intj=0;jn;j++){Node=newPCB;if(Node==NULL)returnfalse;else{cout输入进程的名称,进程需CPU时间:endl;cinNode-procnameNode-needOftime;Node-runtime=0;Node-state=就绪;Node-pri=Node-needOftime;cout进程Node-procname创建完毕!endl;}insert(Node);}returntrue;}voidpriority(inti){run=ready;ready=ready-next;run-state=运行;Prinft(i);while(run!=NULL){run-runtime=run-runtime+1;run-needOftime=run-needOftime-1;run-pri=run-pri-1;if(run-needOftime==0){run-state=完成;run-next=finish;finish=run;run=NULL;if(ready!=NULL){run=ready;run-state=运行;ready=ready-next;}}elseif((ready!=NULL)&&(run-priready-pri)){run-state=就绪;insert(run);run=ready;run-state=运行;ready=ready-next;}display(i);}}voidqueue(PCB*p){if(ready==NULL){p-next=NULL;ready=p;tial=p;}else{tial-next=p;tial=p;p-next=NULL;}}voidRuntime(intc){run=ready;ready=ready-next;run-state=运行;Prinft(c);while(run!=NULL){run-runtime=run-runtime+1;run-needOftime=run-needOftime-1;run-Counter=run-Counter+1;if(run-needOftime==0){run-state=完成;run-next=finish;finish=run;run=NULL;if(ready!=NULL){run=ready;ready=ready-next;}}elseif(run-Counter==run-pieceOftime){run-Counter=0;run-state=就绪;queue(run);run=NULL;if(ready!=NULL){run=ready;run-state=运行;ready=ready-next;}}display(c);}}intmain(){inti;cout----------动态高优先权优先----------endl;cout---------1开始2退出---------\n\n选择:endl;cini;switch(i){case1:CTProcessOfPri();priority(i);break;case2:break;}return0;}voidDtime(intt){time_tcurrent_time;time_tstart_time;time(&start_time);do{time(¤t_time);}while((current_time-start_time)t);}实验结果: