#includeiostream#includestringusingnamespacestd;classProcess{public:stringProcessName;//½ø³ÌÃû×ÖintTime;//½ø³ÌÐèҪʱ¼äintleval;//½ø³ÌÓÅÏȼ¶intLeftTime;//½ø³ÌÔËÐÐÒ»¶Îʱ¼äºó»¹ÐèÒªµÄʱ¼ä};//////////////////////////////////////////////////////voidCopy(Processproc1,Processproc2);//°Ñproc2¸³Öµ¸øproc1voidSort(Processpr[],intsize);//´ËÅÅÐòºó°´ÓÅÏȼ¶´Ó´óµ½Ð¡ÅÅÁÐvoidsort1(Processpr[],intsize);//´ËÅÅÐòºó°´ÐèÒªµÄcpuʱ¼ä´ÓСµ½´óÅÅÁÐvoidFcfs(Processpr[],intnum,intTimepice);//ÏÈÀ´ÏÈ·þÎñËã·¨voidTimeTurn(Processprocess[],intnum,intTimepice);//ʱ¼äƬÂÖתËã·¨voidPriority(Processprocess[],intnum,intTimepice);//ÓÅÏȼ¶Ëã·¨//////////////////////////////////////////////////////////////////////////voidmain(){inta;coutendl;coutÑ¡Ôñµ÷¶ÈËã·¨£ºendl;cout1:FCFS2:ʱ¼äƬÂÖ»»3:ÓÅÏȼ¶µ÷¶È4:×î¶Ì×÷ÒµÓÅÏÈendl;cina;constintSize=30;Processprocess[Size];intnum;intTimePice;coutÊäÈë½ø³Ì¸öÊý:endl;cinnum;coutÊäÈë´Ë½ø³Ìʱ¼äƬ´óС:endl;cinTimePice;for(inti=0;inum;i++){stringname;intCpuTime;intLeval;coutÊäÈëµÚi+1¸ö½ø³ÌµÄÃû×Ö¡¢cpuʱ¼äºÍÓÅÏȼ¶:endl;cinname;cinCpuTimeLeval;process[i].ProcessName=name;process[i].Time=CpuTime;process[i].leval=Leval;coutendl;}for(intk=0;knum;k++)process[k].LeftTime=process[k].Time;//¶Ô½ø³ÌÊ£Óàʱ¼ä³õʼ»¯cout(˵Ã÷:ÔÚ±¾³ÌÐòËùÁнø³ÌÐÅÏ¢ÖУ¬ÓÅÏȼ¶Ò»ÏîÊÇÖ¸½ø³ÌÔËÐкóµÄÓÅÏȼ¶!!);coutendl;coutendl;cout½ø³ÌÃû×Ö¹²ÐèÕ¼ÓÃCPUʱ¼ä»¹ÐèÒªÕ¼ÓÃʱ¼äÓÅÏȼ¶×´Ì¬endl;if(a==1)Fcfs(process,num,TimePice);elseif(a==2)TimeTurn(process,num,TimePice);elseif(a==3){Sort(process,num);Priority(process,num,TimePice);}else//×î¶Ì×÷ÒµËã·¨£¬ÏÈ°´Ê±¼ä´ÓСµ½µ½ÅÅÐò£¬ÔÙµ÷ÓÃFcfsËã·¨¼´¿É{sort1(process,num);Fcfs(process,num,TimePice);}}/////////////////////////////////voidCopy(Processproc1,Processproc2){proc1.leval=proc2.leval;proc1.ProcessName=proc2.ProcessName;proc1.Time=proc2.Time;}/////////////////////////////////////////////voidSort(Processpr[],intsize)//ÒÔ½ø³ÌÓÅÏȼ¶¸ßµÍÅÅÐò{//Ö±½Ó²åÈëÅÅÐòfor(inti=1;isize;i++){Processtemp;temp=pr[i];intj=i;while(j0&&temp.levalpr[j-1].leval){pr[j]=pr[j-1];j--;}pr[j]=temp;}//Ö±½Ó²åÈëÅÅÐòºó½ø³Ì°´ÓÅÏȼ¶´ÓСµ½´óÅÅÁÐfor(intd=size-1;dsize/2;d--){Processtemp;temp=pr[d];pr[d]=pr[size-d-1];pr[size-d-1]=temp;}//´ËÅÅÐòºó°´ÓÅÏȼ¶´Ó´óµ½Ð¡ÅÅÁÐ}///////////////////////////////////////////////////voidsort1(Processpr[],intsize)//ÒÔ½ø³Ìʱ¼ä´ÓµÍµ½¸ßÅÅÐò{//Ö±½Ó²åÈëÅÅÐòfor(inti=1;isize;i++){Processtemp;temp=pr[i];intj=i;while(j0&&temp.Timepr[j-1].Time){pr[j]=pr[j-1];j--;}pr[j]=temp;}}////////////////////////////////////////ÏÈÀ´ÏÈ·þÎñËã·¨µÄʵÏÖ/////////////////////////////////voidFcfs(Processprocess[],intnum,intTimepice){//process[]ÊÇÊäÈëµÄ½ø³Ì£¬numÊǽø³ÌµÄÊýÄ¿£¬TimepiceÊÇʱ¼äƬ´óС//while(true){if(num==0){coutËùÓнø³Ì¶¼ÒѾִÐÐÍê±Ï!endl;exit(1);}if(process[0].LeftTime==0){cout½ø³Ìprocess[0].ProcessNameÒѾִÐÐÍê±Ï!endl;for(inti=0;inum;i++)process[i]=process[i+1];num--;}elseif(process[num-1].LeftTime==0){cout½ø³Ìprocess[num-1].ProcessNameÒѾִÐÐÍê±Ï!endl;num--;}else{coutendl;//Êä³öÕýÔÚÔËÐеĽø³Ìprocess[0].LeftTime=process[0].LeftTime-Timepice;process[0].leval=process[0].leval-1;coutprocess[0].ProcessNameprocess[0].Time;coutprocess[0].LeftTimeprocess[0].levalÔËÐÐ;coutendl;for(ints=1;snum;s++){coutprocess[s].ProcessNameprocess[s].Time;coutprocess[s].LeftTimeprocess[s].levalµÈ´ýendl;;}}//elsecoutendl;system(pause);coutendl;}//while}//////////////////////////////////////////////////////ʱ¼äƬÂÖתµ÷¶ÈË㷨ʵÏÖ//////////////////////////////////////////////voidTimeTurn(Processprocess[],intnum,intTimepice){while(true){if(num==0){coutËùÓнø³Ì¶¼ÒѾִÐÐÍê±Ï!endl;exit(1);}if(process[0].LeftTime==0){cout½ø³Ìprocess[0].ProcessNameÒѾִÐÐÍê±Ï!endl;for(inti=0;inum;i++)process[i]=process[i+1];num--;}if(process[num-1].LeftTime==0){cout½ø³Ìprocess[num-1].ProcessNameÒѾִÐÐÍê±Ï!endl;num--;}elseif(process[0].LeftTime0){coutendl;//Êä³öÕýÔÚÔËÐеĽø³Ìprocess[0].LeftTime=process[0].LeftTime-Timepice;process[0].leval=process[0].leval-1;coutprocess[0].ProcessNameprocess[0].Time;coutprocess[0].LeftTimeprocess[0].levalÔËÐÐ;coutendl;for(ints=1;snum;s++){coutprocess[s].ProcessNameprocess[s].Time;coutprocess[s].LeftTimeprocess[s].leval;if(s==1)cout¾ÍÐ÷endl;elsecoutµÈ´ýendl;}Processtemp;temp=process[0];for(intj=0;jnum;j++)process[j]=process[j+1];process[num-1]=temp;}//elsecoutendl;system(pause);coutendl;}//while}///////////////////////////////////////////////////////ÓÅÏȼ¶µ÷¶ÈËã·¨µÄʵÏÖ////////////////////////////////////////////////voidPriority(Processprocess[],intnum,intTimepice){while(true){if(num==0){coutËùÓнø³Ì¶¼ÒѾִÐÐÍê±Ï!endl;exit(1);}if(process[0].LeftTime==0){cout½ø³Ìprocess[0].ProcessNameÒѾִÐÐÍê±Ï!endl;for(intm=0;mnum;m++)process[m]=process[m+1];//Ò»¸ö½ø³ÌÖ´ÐÐÍê±Ïºó´ÓÊý×éÖÐɾ³ýnum--;//´Ëʱ½ø³ÌÊýÄ¿¼õÉÙÒ»¸ö}if(num!=1&&process[num-1].LeftTime==0){cout½ø³Ìprocess[num-1].ProcessNameÒѾִÐÐÍê±Ï!endl;num--;}if(process[0].LeftTime0){coutendl;//Êä³