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

Process Scheduling in C++

Uploaded by

ms.inahus
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)
3 views1 page

Process Scheduling in C++

Uploaded by

ms.inahus
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

#include <iostream>

using namespace std;

int main() {
int n;
cout << "Enter number of processes: ";
cin >> n;

int bt[20], at[20], wt[20], tat[20], ct[20];


for (int i = 0; i < n; ++i) {
cout << "Burst time of P" << i+1 << ": ";
cin >> bt[i];
cout << "Arrival time of P" << i+1 << ": ";
cin >> at[i];
}

ct[0] = at[0] + bt[0];


for (int i = 1; i < n; ++i)
ct[i] = max(ct[i-1], at[i]) + bt[i];

float avgWT = 0, avgTAT = 0;

cout << "\nP\tAT\tBT\tCT\tTAT\tWT\n";


for (int i = 0; i < n; ++i) {
tat[i] = ct[i] - at[i];
wt[i] = tat[i] - bt[i];
avgWT += wt[i];
avgTAT += tat[i];

cout << "P" << i+1 << '\t'


<< at[i] << '\t'
<< bt[i] << '\t'
<< ct[i] << '\t'
<< tat[i] << '\t'
<< wt[i] << '\n';
}

cout << "Average WT = " << avgWT / n << endl;


cout << "Average TAT = " << avgTAT / n << endl;

return 0;
}

You might also like