Question
*correct the following code in c++ by adding or removing from it to satisfy this question *Include 2 runs of the program. please include the
*correct the following code in "c++" by adding or removing from it to satisfy this question
*Include 2 runs of the program. please include the screenshots
*Write a program in c++ or java that simulates the FCFS (first-come, first-served), SJF (shortest-job-first), SRTF (shortest-remaining-time-first), RR (round-robin) and Priority CPU scheduling algorithms. Create a separate Class for the jobs. Each job has a ID, Arrival time, Burst Time, and Priority. Randomly generate the job details for 10 jobs (the IDs should be generated in a sequence i.e., ID#1, ID#2, , ID#10). Arrival time should be between 0 and 10, Burst time between 1 and 20 seconds, and priority between 1 and 10 (lower value has higher priority i.e., 1 has more priority than 5). For jobs with the same priority, give preference to arrival time. For the RR scheduling, assume the time quantum or time slice to be 3 seconds. Execute the same set of jobs for each of the algorithms. Report the average waiting time and average turnaround time for each scheduling algorithm. The program can be implemented either in C++ or Java. Include 2 runs of the program. please include the screenshots
cpushc.h
#ifndef CPUSHC_H #define CPUSHC_H
#include
cpushc.cpp
#include "cpushc.h" // Implementation file for Cpu scheduling
#include
//First come First served Algorithm void cpuschedule::Fcfs() { int i,B[10]; Twt=0.0; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process p"<
//Calculating Average Weighting Time for(i=1;i<=n;i++) Twt=Twt+Wt[i]; Awt=Twt/n; cout<<"Total Weighting Time="< //Shortest job First Algorithm void cpuschedule::Sjf() { int i,j,temp,B[10]; Twt=0.0; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process p"<=1;i--) { for(j=1;j<=n;j++) { if(B[j-1]>B[j]) { temp=B[j-1]; B[j-1]=B[j]; B[j]=temp; } } } Wt[1]=0; for(i=2;i<=n;i++) { Wt[i]=B[i-1]+Wt[i-1]; } //calculating Average Weighting Time for(i=1;i<=n;i++) Twt=Twt+Wt[i]; Awt=Twt/n; cout<<"Total Weighting Time="< //Shortest job First Algorithm with NonPreemption void cpuschedule::SjfNp() { int i,B[10],Tt=0,temp,j; char S[10]; float A[10],temp1,t; Twt=0.0; w=0.0; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process p"< //For the 1st process Wt[1]=0; w=w+B[1]; t=w; S[1]='F'; while(w for(i=1;i<=n;i++) cout<<"Wt"< //calculating average weighting Time for(i=1;i<=n;i++) Twt=Twt+(Wt[i]-A[i]); Awt=Twt/n; cout<<"Total Weighting Time="< //Priority Algorithm void cpuschedule::Priority() { int i,B[10],P[10],j; w=0.0; int max; Twt=0.0; max=1; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process p"<>P[i]; if(max //calculating average weighting Time for(i=1;i<=n;i++) Twt=Twt+Wt[i]; Awt=Twt/n; cout<<"Total Weighting Time="< //Shortest job First Algorithm with Preemption void cpuschedule::SjfP() { int i,j,m,Wt[10],k,B[10],A[10],Tt=0,Wtm[10],temp; char S[20],start[20]; int max=0,Time=0,min; float Twt=0.0,Awt; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<"Burst time for process P"<max) max=B[i]; Wt[i]=0; S[i]='T'; start[i]='F'; Tt=Tt+B[i]; cout<<"Enter the Arrival Time for"<B[j] && A[j]<=t && i!=j ) { flag=0; Wt[i]=Wt[i]-w; i=j; } else { flag=1; } j++; } } else { i++; j=1; while(A[j]<=t &&j<=n) { if(B[i]>B[j] && S[j]!='F') { flag=0; i=j; } j++; } } } else if(flag==0) i++; } cout<<"Printing remaining burst time"; for(i=1;i<=n;i++) cout<<"B["< while(wB[i] && S[i]=='T') { min=B[i]; j=i; } i++; } i=j; if(w==Time && start[i]=='T') { w=w+B[i]; S[i]='F'; } else { Wt[i]=Wt[i]+w; w=w+B[i]; S[i]='F'; } } cout<<"Weight info"; for(i=1;i<=n;i++) cout<<"WT["< //calculating Average Weighting Time for(i=1;i<=n;i++) Twt=Twt+Wt[i]; Awt=Twt/n; cout<<"Total Weighting Time="< main.cpp //Application file for cpu Scheduling #include
Step 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