#include #include using namespace std; void findAvgTime(int processes[], int n, int bt[], int at[]) { int wt[n]; int tat[n]; int rt[n]; bool first_response[n]; int remaining_time[n]; int completed = 0, current_time = 0; for (int i = 0; i < n; i++) { remaining_time[i] = bt[i]; first_response[i] = false; } while (completed < n) { int idx = -1; int min_remaining_time = INT_MAX; for (int i = 0; i < n; i++) { if (at[i] <= current_time && remaining_time[i] > 0 && remaining_time[i] < min_remaining_time) { min_remaining_time = remaining_time[i]; idx = i; } } if (idx != -1) { if (!first_response[idx]) { rt[idx] = current_time - at[idx]; first_response[idx] = true; } remaining_time[idx]--; current_time++; if (remaining_time[idx] == 0) { completed++; tat[idx] = current_time - at[idx]; wt[idx] = tat[idx] - bt[idx]; } } else { current_time++; } } cout << "Processes Burst time Arrival time Waiting time Turnaround time Response time\n"; for (int i = 0; i < n; i++) { cout << " " << processes[i] << "\t\t" << bt[i] << "\t " << at[i] << "\t\t" << wt[i] << "\t\t " << tat[i] << "\t\t " << rt[i] << endl; } float total_wt = 0, total_tat = 0, total_rt = 0; for (int i = 0; i < n; i++) { total_wt += wt[i]; total_tat += tat[i]; total_rt += rt[i]; } cout << "Average waiting time = " << total_wt / n << endl; cout << "Average turnaround time = " << total_tat / n << endl; cout << "Average response time = " << total_rt / n << endl; } int main() { int n; cout << "Enter the number of processes: "; cin >> n; int processes[n]; int burst_time[n]; int arrival_time[n]; for (int i = 0; i < n; i++) { processes[i] = i + 1; cout << "Enter burst time for process " << processes[i] << ": "; cin >> burst_time[i]; cout << "Enter arrival time for process " << processes[i] << ": "; cin >> arrival_time[i]; } findAvgTime(processes, n, burst_time, arrival_time); return 0; }