C++ Write a computer program to simulate Round Robin scheduling Round Robin -Pro
ID: 3686610 • Letter: C
Question
C++ Write a computer program to simulate Round Robin scheduling
Round Robin
-Process Arrives
-They have different arrival times. Generate task arrival with random arrival times and random service time. Use the rand function to generate values.
Upon arrival, a process is appended at the end of the ready queue, top of the queue, or right after the current process which is in service at the time of arrival
Process Has:
ID
Service time
Arrival Time
-As time progresses, process will have
Start time, wait time, accumulated time, end time etc.
As time goes on, processes will be picked up by the dispatcher one at a time from the ready queue and will be allowed to execute for one quantum
Quantum will be a variable, use quantum = 10
Have a variable for context switch CS, use CS = 0. Your program should be able to use any value for CS.
Main program will call the various subprograms as needed
Main program should also have a variable to represent clock time
If a process completes before the time quantum has been finished, do not waste the time just doing nothing. Let another process execute following RR algorithm.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
//process declared as struct data type
struct process
{
int no;
int at,et,wt,tt;
int tet;
int t;
};
void main()
{
process p[99];
int i,j,k;
cout<<" Enter No of Processes:";
int np;
cin>>np;
for (i=0;i<np;i++)
{
cout<<" Enter Execution time of process"<<i+1<<":";
cin>>p[i].et;
p[i].tet=p[i].et;
p[i].at=p[i].t=p[i].tt=p[i].wt=0;
p[i].no=i+1;
}
cout<<" Enter Time Quantum:";
int q;
cin>>q;
cout<<" Entered Data";
cout<<" Process ET";
for(i=0;i<np;i++)
{
cout<<" "<<p[i].no<<" "<<p[i].et;
}
int totaltime=0;
for(i=0;i<np;i++)
{
totaltime+=p[i].et;
}
i=0;
k=0;
int rrg[99];
for(j=0;j<totaltime;j++)
{
if((k==0)&&(p[i].et!=0))
{
p[i].wt=j;
if((p[i].t!=0))
{
p[i].wt-=q*p[i].t;
}
}
if((p[i].et!=0)&&(k!=q))
{
rrg[j]=p[i].no;
p[i].et-=1;
k++;
}
else
{
if((k==q)&&(p[i].et!=0))
{
p[i].t+=1;
}
i=i+1;
if(i==np)
{
i=0;
}
k=0;
j=j-1;
}
}
/*
for(j=0;j<totaltime;j++)
{
cout<<" "<<rrg[j];
}
*/
int twt=0;
int ttt=0;
cout<<" Result Of Round Robin";
cout<<" PNo ET WT TT";
for(i=0;i<np;i++)
{
p[i].tt=p[i].wt+p[i].tet;
ttt+=p[i].tt;
twt+=p[i].wt;
cout<<" "<<p[i].no<<" "<<" "<<p[i].tet<<" "<<p[i].wt<<" "<<p[i].tt;
}
cout<<" Average Waiting Time:"<<(float)twt/np;
cout<<" Average Turn Around Time:"<<(float)ttt/np;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.