Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

correct the following code by adding or removing from it to setisfy this question Include 2 runs of the program. please include the screenshots Write

correct the following code by adding or removing from it to setisfy 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 #include #include using namespace std; class cpuschedule { int n,Bu[20]; float Twt,Awt,A[10],Wt[10],w; public: //Getting the No of processes & burst time void Getdata(); //First come First served Algorithm void Fcfs(); //Shortest job First Algorithm void Sjf(); //Shortest job First Algorithm with Preemption void SjfP(); //Shortest job First Algorithm with NonPreemption void SjfNp(); //Round Robin Algorithm void RoundRobin(); //Priority Algorithm void Priority(); }; #endif

cpushc.cpp

#include "cpushc.h" // Implementation file for Cpu scheduling

#include #include #include using namespace std; //Getting no of processes and Burst time void cpuschedule::Getdata() { int i; cout<<"Enter the no of processes:"; cin>>n; for(i=1;i<=n;i++) { cout<<"Enter The BurstTime for Process p"<>Bu[i]; } }

//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

//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"<

//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"<

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["<

main.cpp

//Application file for cpu Scheduling

#include #include #include #include "cpushc.h" using namespace std; int main() { int ch,cho; cpuschedule c; do { cout<<" MENU"; cout<<" 1.Getting BurstTime"; cout<<" 2.FirstComeFirstServed"; cout<<" 3.ShortestJobFirst"; cout<<" 4.RoundRobin"; cout<<" 5.Priority"; cout<<" 6.EXIT"; cout<<" Enter your choice "; cin>>ch; switch(ch) { case 1: c.Getdata(); break; case 2: std::cout<<"FIRST COME FIRST SERVED SCHEDULING"; c.Fcfs(); break; case 3: std::cout<<"SHORTEST JOB FIRST SCHEDULING"; do { std::cout<<"1.SJF-Normel"; std::cout<<"2.SJF-Preemptive"; std::cout<<"3.SJF-NonPreemptive"; std::cout<<"Enter your choice"; std::cin>>cho; switch(cho) { case 1: c.Sjf(); break; case 2: c.SjfP(); break; case 3: c.SjfNp(); break; } }while(cho<=3); break; case 4: std::cout<<"ROUND ROBIN SCHEDULING"; c.RoundRobin(); break; case 5: std::cout<<"PRIORITY SCHEDULING"; c.Priority(); break; case 6: break; } }while(ch<=5); }

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

Define the term Working Capital Gap.

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago