#include #include #include #include //const int MAXJOB=50; // maximum number of jobs #define MAXJOB 50 //data structure of jobs typedef struct node { int number; // job number int reach_time;// arrival time int need_time;// execution time int privilege;// priority float excellent;// response ratio int start_time;// start time int wait_time;// waiting time int visited;// if the job is accessed bool isreached;// if the job has arrived } job; job jobs[MAXJOB];//job sequence int quantity;//number of jobs //initialize job sequence void initial_jobs() { int i; for(i=0;ijobs[i].need_time&&jobs[i].visited==0&&jobs[i].isreached==true) { minjob=jobs[i].need_time; minloc=i; } } return minloc; } //Find the job that arrived ealiest int findrearlyjob(job jobs[],int count) { int rearlyloc=-1; int rearlyjob=-1; for(int i=0;ijobs[i].reach_time&&jobs[i].visited==0) { rearlyjob=jobs[i].reach_time; rearlyloc=i; } } return rearlyloc; } //read all job data void readJobdata() { FILE *fp; char fname[20]; int i; //input the name of test file printf("please input job data file name\n"); scanf("%s",fname); if((fp=fopen(fname,"r"))==NULL) { printf("error, open file failed, please check filename:\n"); } else { //read job information sequentially while(!feof(fp)) { if(fscanf(fp,"%d %d %d %d",&jobs[quantity].number,&jobs[quantity].reach_time,&jobs[quantity].need_time,&jobs[quantity].privilege)==4) quantity++; } //print job information printf("output the origin job data\n"); printf("---------------------------------------------------------------------\n"); printf("\tjobID\treachtime\tneedtime\tprivilege\n"); for(i=0;icurrent_time) { jobs[loc].start_time=jobs[loc].reach_time; current_time=jobs[loc].reach_time; } else { jobs[loc].start_time=current_time; } jobs[loc].wait_time=current_time-jobs[loc].reach_time; printf("\t%-8d\t%-8d\t%-8d\t%-8d\t%-8d\n",loc+1,jobs[loc].reach_time,jobs[loc].start_time,jobs[loc].wait_time, jobs[loc].wait_time+jobs[loc].need_time); jobs[loc].visited=1; current_time+=jobs[loc].need_time; total_waitime+=jobs[loc].wait_time; total_roundtime=total_roundtime+jobs[loc].wait_time+jobs[loc].need_time; // Get the first arriving job among the remaining jobs loc=findrearlyjob(jobs,quantity); } printf("total waiting time:%-8d total turnaround time:%-8d\n", total_waitime, total_roundtime); printf("average waiting time: %4.2f average turnaround time: %4.2f\n", (float)total_waitime/(quantity),(float)total_roundtime/(quantity)); } // Shortest-Job-First Scheduling algorithm. void SFJschdulejob(job jobs[],int count) { } // Highest Response Ratio Next //response ratio=turnaround time/execution time void HRRFschdulejob() { } // Priority scheduling algorithm void HPF(job jobs[]) { } void main() { initial_jobs(); readJobdata(); FCFS(); reset_jinfo(); SFJschdulejob(jobs, quantity); system("pause"); //return 0; }