Program to illustrate round robin scheduling algorithm - Computer Programming

# Computer Programming

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

## Monday, April 4, 2011

//Program to illustrate round robin scheduling algorithm

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
clrscr();
char *pro;
int i,j=0,k=0,n,*burst,time,count=0,*wait,*rem,temp=0;
float sum=0;
cout<<"\n\nEnter no. of processes : ";
cin>>n;
pro=new char[n];
burst=new int[n];
wait=new int[n];
rem=new int[n];
cout<<"Enter process names  : ";       //reading process names
for(i=0;i<n;i++)
{
cin>>pro[i];

}
cout<<"\nEnter burst times : ";

{
cin>>burst[i];
rem[i]=burst[i];
j=j+burst[i];
wait[i]=0;

}
cout<<"\nEnter the time quantum for round robin scheduling : ";
cin>>time;

for(i=1;i<=j;i++)
{

k++;
while(rem[count]==0)
{
if(count==n-1)
count=0;
else
count++;
if(i==j)
break;
}
//cout<<"\nat time : "<<i<<" running process : "<<pro[count];
for(temp=0;temp<n;temp++)             //calculating waiting time
{

if((temp!=count)&&rem[temp]!=0)
wait[temp]++;

}
rem[count]--;
if(k==time||rem[count]==0)
{

cout<<" "<<pro[count]<<"  "<<i;
if(count==n-1)
count=0;
else
count++;
k=0;

}

//cout<<"\nrem time of "<<pro[count]<<" = "<<rem[count];

}

for(i=0;i<n;i++)
{
cout<<"\nWaiting time for process "<<pro[i]<<" = "<<wait[i];
sum=sum+wait[i];

}
cout<<"\nAverage waiting time : "<<sum/n;
getch();
return 0;
}