#include using namespace std; struct Process { int id; // Process ID int burstTime; // Burst Time int arrivalTime; // Arrival Time }; void findWaitingTime(Process processes[], int n, int waitingTime[]) { waitingTime[0] = 0; // Waiting time for the first process is always 0 for (int i = 1; i < n; i++) { waitingTime[i] = processes[i - 1].burstTime + waitingTime[i - 1]; } } void findTurnaroundTime(Process processes[], int n, int waitingTime[], int turnaroundTime[]) { for (int i = 0; i < n; i++) { turnaroundTime[i] = processes[i].burstTime + waitingTime[i]; } } void findAverageTime(Process processes[], int n) { int waitingTime[n], turnaroundTime[n]; int totalWaitingTime = 0, totalTurnaroundTime = 0, totalResponseTime = 0; // Calculate waiting times for each process findWaitingTime(processes, n, waitingTime); // Calculate turnaround times for each process findTurnaroundTime(processes, n, waitingTime, turnaroundTime); // Calculate total waiting, turnaround, and response times for (int i = 0; i < n; i++) { totalWaitingTime += waitingTime[i]; totalTurnaroundTime += turnaroundTime[i]; totalResponseTime += waitingTime[i]; // Response Time = Waiting Time in FCFS } // Calculate and display averages float averageWaitingTime = (float)totalWaitingTime / n; float averageTurnaroundTime = (float)totalTurnaroundTime / n; float averageResponseTime = (float)totalResponseTime / n; cout << "Average Turnaround Time: " << averageTurnaroundTime << endl; cout << "Average Waiting Time: " << averageWaitingTime << endl; cout << "Average Response Time: " << averageResponseTime << endl; } int main() { Process processes[] = {{1, 24, 0}, {2, 3, 0}, {3, 3, 0}}; int n = sizeof(processes) / sizeof(processes[0]); findAverageTime(processes, n); return 0; }