#include #include #include using namespace std; struct Process { int id; int burstTime; int remainingTime; int waitingTime = 0; int turnaroundTime = 0; }; void roundRobinScheduling(vector& processes, int quantum) { queue readyQueue; for (auto& process : processes) { process.remainingTime = process.burstTime; readyQueue.push(&process); } int time = 0; while (!readyQueue.empty()) { Process* current = readyQueue.front(); readyQueue.pop(); int execTime = min(quantum, current->remainingTime); time += execTime; current->remainingTime -= execTime; for (auto& p : processes) { if (&p != current && p.remainingTime > 0) { p.waitingTime += execTime; } } if (current->remainingTime > 0) { readyQueue.push(current); } else { current->turnaroundTime = time; } } cout << "\nProcess\tBurst Time\tWaiting Time\tTurnaround Time\n"; for (const auto& process : processes) { cout << "P" << process.id << "\t\t" << process.burstTime << "\t\t" << process.waitingTime << "\t\t" << process.turnaroundTime << 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 burst time for process " << i + 1 << ": "; cin >> processes[i].burstTime; } cout << "Enter time quantum: "; cin >> quantum; roundRobinScheduling(processes, quantum); return 0; }