-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathround_robin.cpp
More file actions
61 lines (53 loc) · 1.78 KB
/
round_robin.cpp
File metadata and controls
61 lines (53 loc) · 1.78 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
#include <iostream>
int main() {
int NOP, sum = 0, count = 0, y, quant, wt = 0, tat = 0;
float avg_wt, avg_tat;
int tbt=0;
std::cout << "Total number of processes in the system: ";
std::cin >> NOP;
y = NOP;
int at[NOP], bt[NOP], temp[NOP];
int i;
for ( i = 0; i < NOP; i++) {
std::cout << "\nEnter the Arrival and Burst time of Process[" << i + 1 << "]:\n";
std::cout << "Arrival time: ";
std::cin >> at[i];
std::cout << "Burst time: ";
std::cin >> bt[i];
tbt+=bt[i];
temp[i] = bt[i];
}
std::cout << "Enter the Time Quantum for the process: ";
std::cin >> quant;
std::cout << "\nProcess No \t Burst Time \t TAT \t Waiting Time\n";
for (sum = 0, i = 0; y != 0 ;) {
if (temp[i] <= quant && temp[i] > 0) {
sum = sum + temp[i];
temp[i] = 0;
count = 1;
} else if (temp[i] > 0) {
temp[i] = temp[i] - quant;
sum = sum + quant;
}
if (temp[i] == 0 && count == 1) {
y--;
std::cout << "Process No[" << i + 1 << "]\t\t" << bt[i] << "\t\t" << sum - at[i] << "\t\t" << sum - at[i] - bt[i] << "\n";
wt = wt + sum - at[i] - bt[i];
tat = tat + sum - at[i];
count = 0;
}
if (i == NOP - 1) {
i = 0;
} else if (at[i + 1] <= sum) {
i++;
} else {
i = 0;
}
}
avg_wt = static_cast<float>(wt) / NOP;
avg_tat = static_cast<float>(tat) / NOP;
std::cout << "\nAverage Turn Around Time: " << avg_wt << "\n";
std::cout << "Average Waiting Time: " << avg_tat << "\n";
std::cout<<"Throughput:"<<(float)NOP/tbt;
return 0;
}