- #include <stdio.h>
- struct fcfs{
- char name[10];
- float arrivetime;
- float servicetime;
- float starttime;
- float finishtime;
- float zztime;
- float dqzztime;
- };
- fcfs a[100];
- void input(fcfs *p,int N)
- { int i;
- printf("intput the process's name & arrivetime & servicetime:/nfor exmple: a 0 100/n");
- for(i=0;i<=N-1;i++)
- {
- printf("input the %dth process's information:/n",i+1);
- scanf("%s%f%f",&p[i].name,&p[i].arrivetime,&p[i].servicetime);
- /* printf("input the %dth process's arrivetime:/n",i+1);
- scanf("%f",&p[i].arrivetime);
- printf("input the %dth process's servicetime:/n",i+1);
- scanf("%f",&p[i].servicetime);
- */
- }
- }
- void Print(fcfs *p,float arrivetime,float servicetime,float starttime,float finishtime,float zztime,float dqzztime,int N)
- {int k;
- printf("run order:");
- printf("%s",p[0].name);
- for(k=1;k<N;k++)
- {printf("-->%s",p[k].name);
- }
- printf("/nthe process's information:/n");
- printf("/nname/tarrive/tservice/tstart/tfinish/tzz/tdqzz/n");
- for(k=0;k<=N-1;k++)
- { printf("%s/t%-.2f/t%-.2f/t%-.2f/t%-.2f/t%-.2f/t%-.2f/t/n",p[k].name,p[k].arrivetime,p[k].servicetime,p[k].starttime,p[k].finishtime,p[k].zztime,p[k].dqzztime);
- /*
- printf("/nname:%s/t",p[k].name);
- printf("/narrivetime:%-.2f/t",p[k].arrivetime);
- printf("/nservicetime:%-.2f/t",p[k].servicetime);
- printf("/nstarttime:%-.2f/t",p[k].starttime);
- printf("/nfinishtime:%-.2f/t",p[k].finishtime);
- printf("/nzztime:%-.2f/t",p[k].zztime);
- printf("/ndqzztime:%-.2f/t/n",p[k].dqzztime);*/
- }
- }
- //pai xu
- void sort(fcfs *p,int N)
- {
- for(int i=0;i<=N-1;i++)
- for(int j=0;j<=i;j++)
- if(p[i].arrivetime<p[j].arrivetime)
- {
- fcfs temp;
- temp=p[i];
- p[i]=p[j];
- p[j]=temp;
- }
- }
- //yun xing jieduan
- void deal(fcfs *p, float arrivetime,float servicetime,float starttime,float finishtime,float &zztime,float &dqzztime,int N)
- { int k;
- for(k=0;k<=N-1;k++)
- {
- if(k==0)
- {
- p[k].starttime=p[k].arrivetime;
- p[k].finishtime=p[k].arrivetime+p[k].servicetime;}
- else
- {
- p[k].starttime=p[k-1].finishtime;
- p[k].finishtime=p[k-1].finishtime+p[k].servicetime;}
- }
- for(k=0;k<=N-1;k++)
- {
- p[k].zztime=p[k].finishtime-p[k].arrivetime;
- p[k].dqzztime=p[k].zztime/p[k].servicetime;
- }
- }
- void FCFS(fcfs *p,int N)
- {
- float arrivetime=0,servicetime=0,starttime=0,finishtime=0,zztime=0,dqzztime=0;
- sort(p,N);
- deal(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);
- Print(p,arrivetime,servicetime,starttime,finishtime,zztime,dqzztime,N);
- }
- void main()
- { int N;
- printf("------先来先服务调度算法------/n");
- printf("input the process's number:/n");
- scanf("%d",&N);
- input(a,N);
- FCFS(a,N);
- }