Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #define Size 30 #include using namespace std; struct node{ int arrival; int burst; int processno; int completiontime; int priority; int turnAround; int waiting; struct node *next; }; struct node* createNode(int processes, int arrivaltime, int bursttime, int prioritytime){ struct node *temp; temp= (struct node*) malloc(sizeof(node)); temp->processno = processes; temp->arrival = arrivaltime; temp->burst = bursttime; temp->priority = prioritytime; temp->next = NULL; } struct node* insertBack(struct node* header,int processes, int arrivaltime, int bursttime, int prioritytime){ struct node *temp = createNode(processes, arrivaltime, bursttime, prioritytime); struct node *headertemp; if(header == NULL){ header = temp; return header; } headertemp = header; while(headertemp->next!=NULL) headertemp = headertemp->next; headertemp->next = temp; return header; } struct node *readFile(struct node *header){

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;image text in transcribed

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 ms

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago