230101098-lab3
230101098-lab3
230101098
#include <iostream>
struct Process {
int id, arrival, burst, completion, turnaround, waiting;
};
int main() {
int n;
cout << "Enter the number of processes: ";
cin >> n;
Process processes[n];
if (idx == -1) {
time++;
} else {
processes[idx].completion = time + processes[idx].burst;
processes[idx].turnaround = processes[idx].completion - processes[idx].arrival;
processes[idx].waiting = processes[idx].turnaround - processes[idx].burst;
time += processes[idx].burst;
completed++;
}
}
cout << "\nAverage Turnaround Time: " << totalTAT / n << endl;
cout << "Average Waiting Time: " << totalWT / n << endl;
return 0;
}
Output:
Program: Write a program to implement SRTF
#include<iostream>
#include<climits>
using namespace std;
int main() {
int n;
int bt[20], at[20], ct[20], wt[20], pid[20], tat[20], remaining_bt[20];
float avgtat = 0, avgwt = 0;
remaining_bt[shortest]--;
time++;
if (remaining_bt[shortest] == 0) {
ct[shortest] = time;
tat[shortest] = ct[shortest] - at[shortest];
wt[shortest] = tat[shortest] - bt[shortest];
isCompleted[shortest] = true;
completed++;
}
}
avgtat /= n;
avgwt /= n;
cout << "Average Turnaround Time: " << avgtat << endl;
cout << "Average Waiting Time: " << avgwt << endl;
return 0;
}
Output: