-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRR.cpp
More file actions
73 lines (61 loc) · 1.65 KB
/
RR.cpp
File metadata and controls
73 lines (61 loc) · 1.65 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
73
//TOPIC: Implementation of Round robin Scheduling Algorithm
#include <bits/stdc++.h>
using namespace std;
void calculateTAT(int N, int BT[], int BT2[], int TAT[], int QT)
{
cout << "Processing started." << endl;
int count = 0, i = 0;
int remainingProcesses = N;
while (remainingProcesses > 0)
{
if (BT2[i] > 0)
{
if (BT2[i] > QT)
{
count += QT;
BT2[i] -= QT;
}
else
{
count += BT2[i];
BT2[i] = 0;
TAT[i] = count;
remainingProcesses--;
}
}
i = (i + 1) % N;
}
cout << "Processing done." << endl;
}
int main()
{
int pNum;
cout << "Number of processes: ";
cin >> pNum;
int BT[pNum], WT[pNum] = {0}, TAT[pNum] = {0}, QT, BT2[pNum];
for (int i = 0; i < pNum; i++)
{
cout << "Burst Time of process P" << i + 1 << ": ";
cin >> BT[i];
BT2[i] = BT[i];
}
cout << "Put Quantum Time: ";
cin >> QT;
calculateTAT(pNum, BT, BT2, TAT, QT);
double avgWT = 0, avgTAT = 0;
for (int i = 0; i < pNum; i++)
{
WT[i] = TAT[i] - BT[i];
avgTAT += TAT[i];
avgWT += WT[i];
}
avgTAT /= pNum;
avgWT /= pNum;
cout << " P\t\tBT\t\tTAT\t\tWT\n";
for (int i = 0; i < pNum; i++) {
cout << " P" << i + 1 << "\t\t" << BT[i] << "\t\t" << TAT[i] << "\t\t " << WT[i] << endl;
}
cout << "The average Turn around time: " << avgTAT << endl;
cout << "The average Waiting time: " << avgWT << endl;
return 0;
}