-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroundrobin.cpp
More file actions
73 lines (61 loc) · 1.23 KB
/
roundrobin.cpp
File metadata and controls
73 lines (61 loc) · 1.23 KB
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
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
using namespace std;
/*at = Arrival time,
bt = Burst time,
time_quantum= Quantum time
tat = Turn around time,
wt = Waiting time*/
int main()
{
int i,n,time,remain,temps=0,time_quantum;
int wt=0,tat=0;
cout<<"Enter the total number of process"<<endl;
cin>>n;
remain=n;
vector<int>at(n);
vector<int>bt(n);
vector<int>rt(n);
cout<<"Enter the Arrival time, Burst time for All the processes"<<endl;
for(i=0;i<n;i++)
{
cin>>at[i];
cin>>bt[i];
rt[i]=bt[i];
}
cout<<"Enter the value of time QUANTUM"<<endl;
cin>>time_quantum;
cout<<"Time Quantum is:"<<" "<<time_quantum<<'\n';
cout<<"\nProcess \t:Turnaround Time:Waiting Time\n";
for(time=0,i=0;remain!=0;)
{
if(rt[i]<=time_quantum && rt[i]>0)
{
time+=rt[i];
rt[i]=0;
temps=1;
}
else if(rt[i]>0)
{
rt[i]-=time_quantum;
time+=time_quantum;
}
if(rt[i]==0 && temps==1)
{
remain--;
printf("Process{%d}\t:\t%d\t:\t%d\n",i+1,time-at[i],time-at[i]-bt[i]);
cout<<endl;
wt+=time-at[i]-bt[i];
tat+=time-at[i];
temps=0;
}
if(i==n-1)
i=0;
else if(at[i+1]<=time)
i++;
else
i=0;
}
cout<<"Average waiting time "<<wt*1.0/n<<endl;
cout<<"Average turn around time "<<tat*1.0/n<<endl;;
return 0;
}