-
Notifications
You must be signed in to change notification settings - Fork 2
/
Round-Robin.cpp
61 lines (53 loc) · 1.35 KB
/
Round-Robin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostrem.h>
#include<stdio.h>
using namespace std;
int main(){
int i,j,n,max,t_slice,burst_time[i],wait_time[10],turn_around_time[10],c_t[10];
float avg_tat_time,avg_wait_time,temp=0;
clrscr();
cout<<"\nEnter the no. of process:--";
cin<<n;
cout<<"\nEnter the time slice:--";
cin>>t_slice;
cout<<"\nEnter the arrival and burst time:--";
for ( i = 0; i < n; i++)
{ cin>>burst_time[i];
c_t[i]=burst_time[i];
}
max=burst_time[0];
for ( i = 1; i < n; i++)
{
if(max<burst_time[i])
max=burst_time[i];
}
for ( j = 0; j < (max/t_slice)+1; j++)
{
for ( i = 0; i < n; i++)
{
if(burst_time[i]!=0){
if(burst_time[i]<=t_slice){
turn_around_time[i]=temp+burst_time[i];
temp=temp+burst_time[i];
burst_time[i]=0;
}
else{
burst_time[i]-=t_slice;
temp+=t;
}
}
}
}
for ( i = 0; i < n; i++)
{
wait_time[i]=turn_around_time[i]-c_t[i];
avg_tat_time+=turn_around_time[i];
avg_wait_time+=wait_time[i]
}
cout<<"\tPROCESS\tBURST TIME\t WAITING TIME\t TURNAROUND TIME\n";
for(i=0;i<n;i++){
cout<<"\n\tP"<<i<<"\t\t"<<burst_time[i]<<"\t\t"<<wait_time[i]<<"\t\t"<<turn_around_time[i];
}
cout<<"\nAverage Waiting Time --"<<avg_wait_time/n;
cout<<"\nAverage Turnaround Time --"<<avg_tat_time/n;
return 0;
}