#include using namespace std; struct Process { int id; int arrivalTime; int burstTime; int remainingTime; int finishTime; int waitingTime; int turnaroundTime; int responseTime; bool firstResponse; }; void roundRobin(Process processes[], int n, int quantum) { int time = 0; int completed = 0; double totalTurnaroundTime = 0; double totalWaitingTime = 0; double totalResponseTime = 0; while (completed != n) { bool allDone = true; for (int i = 0; i < n; i++) { if (processes[i].arrivalTime <= time && processes[i].remainingTime > 0) { allDone = false; if (processes[i].remainingTime > quantum) { if (processes[i].firstResponse) { processes[i].responseTime = time - processes[i].arrivalTime; processes[i].firstResponse = false; totalResponseTime += processes[i].responseTime; } time += quantum; processes[i].remainingTime -= quantum; } else { if (processes[i].firstResponse) { processes[i].responseTime = time - processes[i].arrivalTime; processes[i].firstResponse = false; totalResponseTime += processes[i].responseTime; } time += processes[i].remainingTime; processes[i].remainingTime = 0; processes[i].finishTime = time; processes[i].turnaroundTime = processes[i].finishTime - processes[i].arrivalTime; processes[i].waitingTime = processes[i].turnaroundTime - processes[i].burstTime; totalTurnaroundTime += processes[i].turnaroundTime; totalWaitingTime += processes[i].waitingTime; completed++; } } } if (allDone) { time++; } } cout << "Average Turnaround Time: " << totalTurnaroundTime / n << endl; cout << "Average Waiting Time: " << totalWaitingTime / n << endl; cout << "Average Response Time: " << totalResponseTime / n << endl; } int main() { int n, quantum; cout << "Enter the number of processes: "; cin >> n; Process processes[n]; for (int i = 0; i < n; i++) { processes[i].id = i + 1; cout << "Enter arrival time of process " << i + 1 << ": "; cin >> processes[i].arrivalTime; cout << "Enter burst time of process " << i + 1 << ": "; cin >> processes[i].burstTime; processes[i].remainingTime = processes[i].burstTime; processes[i].firstResponse = true; } cout << "Enter time quantum: "; cin >> quantum; roundRobin(processes, n, quantum); return 0; }