Question
Please Complete this code on CPU scheduling method, I wrote for the FCFS first serve and I keep getting error I want the output of
Please Complete this code on CPU scheduling method, I wrote for the FCFS first serve and I keep getting error I want the output of the FCFS,SJF,Round Robin, PRIORITY to be displayed in the output.txt text file,.Please use my steps to write this code, I want it completed. Thank you, can you please debug this code.
#include
int process = 1; FILE *fp; char line[Size]; unsigned int num[3]; if((fp = fopen("input.txt","r"))==NULL){ cout"""
fclose(fp); return header; } int is_empty(struct node *header){ if(header==NULL){ return 1; } else return 0; } struct node* sortArrival(struct node* header ){ struct node* temp = header; struct node* i = temp; struct node* j = temp->next; for(i=temp; i != NULL; i = i->next){ for(j=i->next; j != NULL; j = j->next){ if(((i->arrival)) > ((j->arrival))){ struct node* temp2 = createNode(i->processno, i->arrival, i->burst, i->priority); i->processno = j->processno; i->arrival = j->arrival; i->burst = j->burst; i->priority = j->priority; i->waiting = j->waiting; i->turnAround = j->turnAround; i->completiontime = j->completiontime; j->processno = temp2->processno; j->arrival = temp2->arrival; j->burst = temp2->burst; j->priority = temp2->priority; j->waiting = temp2->waiting; j->turnAround = temp2->turnAround; j->completiontime = temp2->completiontime; } } } } void sortProcess(struct node* header){ struct node *temp = header; struct node *i = temp; struct node *j = temp->next; for(i=temp; i != NULL; i = i->next){ for(j=i->next; j!=NULL; j=j->next){ if(((i->processno)) > ((j->processno))){ struct node* temp2 = createNode(i->processno, i->arrival, i->burst, i->priority); i->processno = j->processno; i->arrival = j->arrival; i->burst = j->burst; i->priority = j->priority; i->waiting = j->waiting; i->turnAround = j->turnAround; i->completiontime = j->completiontime; j->processno = temp2->processno; j->arrival = temp2->arrival; j->burst = temp2->burst; j->priority = temp2->priority; j->waiting = temp2->waiting; j->turnAround = temp2->turnAround; j->completiontime = temp2->completiontime; } } } } void display(struct node *header)
{ if (header == NULL) cout
while (temp != NULL) { coutarrival"; temp=temp->next; } cout arrival>currentTime){ currentTime +=1; continue; } currentTime += temp->burst; temp->completiontime = currentTime; temp->turnAround = temp->completiontime - temp->arrival; temp->waiting = temp->turnAround - temp->burst; wt+= temp->waiting; if(temp->next!= NULL) temp=temp->next; else break; } average = (float)wt/process;
sortProcess(header); fstream myFile("output1.txt"); myFileprocessnowaitingnext; display(anothertemp); } myFile
while (fgets(line, Size, fp) != NULL) { sscanf(line,"%d:%d:%d ",&num[0],&num[1],&num[2]); header = insertBack(header,process,num[0],num[1],num[2]); process+1; }
fclose(fp); while (1){ int val; //credting a swtich for scheduling method cout>val; switch(val){ case 1: cout
}
i want the output to be display as follows;
APPENDIX File Input.txt 5:0:3 4:1:2 3:1:1 4:2:2 3:3:1 output.txt/Screen output Scheduling Method: First Come First Served Process Waiting Times: P1: 0 ms P2: 4 ms P3: 8 ms P4: 10 ms P5: 13 ms Average Waiting Time: 7 ms Scheduling Method: Shortest Job First - Non-Preemptive Process Waiting Times: P1: 0 ms P2: 10 ms P3: 4 ms P4: 13 ms P5: 5 ms Average Waiting Time: 6.4 ms Scheduling Method: Shortest Job First - Preemptive Process Waiting Times: P1: 6 ms P2: 10 ms P3: 0 ms P4: 13 ms P5: 1 ms Average Waiting Time: 6 ms Scheduling Method: Priority Scheduling - Non-Preemptive Process Waiting Times: P1: 0 ms P2: 10 ms P3: 4 ms P4: 13 ms P5: 5 ms Average Waiting Time: 6.4 msStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started