#include #include #include #include using namespace std; struct Process { int id; int arrivalTime; int burstTime; int startTime; int finishTime; int remainingTime; int waitingTime; int turnaroundTime; int responseTime; }; void roundRobin(vector& processes, int n, int quantum) { queue readyQueue; int time = 0; int completed = 0; double totalTurnaroundTime = 0; double totalWaitingTime = 0; double totalResponseTime = 0; vector visited(n, false); readyQueue.push(0); visited[0] = true; processes[0].startTime = 0; while (completed != n) { int idx = readyQueue.front(); readyQueue.pop(); if (processes[idx].remainingTime == processes[idx].burstTime) { processes[idx].responseTime = time - processes[idx].arrivalTime; totalResponseTime += processes[idx].responseTime; } if (processes[idx].remainingTime > quantum) { time += quantum; processes[idx].remainingTime -= quantum; } else { time += processes[idx].remainingTime; processes[idx].remainingTime = 0; processes[idx].finishTime = time; processes[idx].waitingTime = processes[idx].finishTime - processes[idx].arrivalTime - processes[idx].burstTime; processes[idx].turnaroundTime = processes[idx].finishTime - processes[idx].arrivalTime; totalWaitingTime += processes[idx].waitingTime; totalTurnaroundTime += processes[idx].turnaroundTime; completed++; } for (int i = 1; i < n; i++) { if (processes[i].arrivalTime <= time && !visited[i] && processes[i].remainingTime > 0) { readyQueue.push(i); visited[i] = true; } } if (processes[idx].remainingTime > 0) { readyQueue.push(idx); } } cout << fixed << setprecision(2); 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; vector 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; } cout << "Enter time quantum: "; cin >> quantum; roundRobin(processes, n, quantum); return 0; }