main.cpp
#include<iostream>
using namespace std;
struct processes
{
int nums;
int arrival,estimated,wait,total;
int est;
int time;
};
int main()
{
processes arr[99];
int x,y,z;
cout<<"Please enter the total number of processes:"<<endl;
int processNum;
cin>>processNum;
for (x=0;x<processNum;x++)
{
cout<<"Please enter the execution time of processes "<<x+1<<":"<<endl;
cin>>arr[x].estimated;
arr[x].est=arr[x].estimated;
arr[x].arrival=arr[x].time=arr[x].total=arr[x].wait=0;
arr[x].nums=x+1;
}
cout<<"Please enter the time quantum:"<<endl;
int a;
cin>>a;
cout<<"The entered data is as follows: "<<endl;
cout<<"Processes\tET"<<endl;
for(x=0;x<processNum;x++)
{
cout<<endl;
cout<<arr[x].nums<<"\t\t\t"<<arr[x].estimated;
}
int totaltime=0;
for(x=0;x<processNum;x++)
{
totaltime+=arr[x].estimated;
}
x=0;
z=0;
int rrg[99];
for(y=0;y<totaltime;y++)
{
if((z==0)&&(arr[x].estimated!=0))
{
arr[x].wait=y;
if((arr[x].time!=0))
{
arr[x].wait-=a*arr[x].time;
}
}
if((arr[x].estimated!=0)&&(z!=a))
{
rrg[y]=arr[x].nums;
arr[x].estimated-=1;
z++;
}
else
{
if((z==a)&&(arr[x].estimated!=0))
{
arr[x].time+=1;
}
x=x+1;
if(x==processNum)
{
x=0;
}
z=0;
y=y-1;
}
}
int waitTotal=0;
int timeTotal=0;
cout<<endl;
cout<<"Final result of round robin scheduling: "<<endl;
cout<<"Process Id\tEstimated Time\tWait Time\tTurn around Time";
for(x=0;x<processNum;x++)
{
arr[x].total=arr[x].wait+arr[x].est;
timeTotal+=arr[x].total;
waitTotal+=arr[x].wait;
cout<<endl;
cout<<arr[x].nums<<"\t\t"<<"\t\t"<<arr[x].est<<"\t\t\t\t"<<arr[x].wait<<"\t\t\t\t"<<arr[x].total<<endl;
}
cout<<endl;
cout<<"Average Waiting Time: "<<(float)waitTotal/processNum<<endl;
cout<<"Average Turn Around Time: "<<(float)timeTotal/processNum<<endl;
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.