0% found this document useful (0 votes)
2 views1 page

RR.cpp

Uploaded by

hm8019158
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

RR.cpp

Uploaded by

hm8019158
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;

int main() {
int n, quantum, bt[20], rem[20], wt[20] = {0}, tat[20], t = 0;
cout << "Enter number of processes: "; cin >> n;
for (int i = 0; i < n; i++) {
cout << "Burst time for process " << i + 1 << ": ";
cin >> bt[i];
rem[i] = bt[i];
}
cout << "Enter time quantum: "; cin >> quantum;

bool done;
do {
done = true;
for (int i = 0; i < n; i++) {
if (rem[i] > 0) {
done = false;
int time = rem[i] > quantum ? quantum : rem[i];
t += time; rem[i] -= time;
if (rem[i] == 0) wt[i] = t - bt[i];
}
}
} while (!done);

int total_wt = 0, total_tat = 0;


cout << "\nProcess\tBT\tWT\tTAT\n";
for (int i = 0; i < n; i++) {
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i];
cout << "P" << i + 1 << "\t" << bt[i] << "\t" << wt[i] << "\t" << tat[i] <<
"\n";
}

cout << "\nAverage Waiting Time = " << (float)total_wt / n;


cout << "\nAverage Turnaround Time = " << (float)total_tat / n << "\n";
}

You might also like