Here's a modified version of the Round Robin scheduling algorithm in C++ that uses predefined arrival times and burst times for 30 jobs. The user can enter different quantum numbers to calculate completion time, waiting time, and turnaround time. The program will also display the average waiting time and average turnaround time for each quantum number.
```cpp
#include <iostream>
#include <vector>
#include <queue>
struct Job {
int arrivalTime;
int burstTime;
int remainingTime;
};
void roundRobinScheduling(std::vector<Job>& jobs, int quantum) {
std::queue<Job> readyQueue;
int currentTime = 0;
int totalJobs = jobs.size();
int totalWaitingTime = 0;
int totalTurnaroundTime = 0;
for (int i = 0; i < totalJobs; i++) {
jobs[i].remainingTime = jobs[i].burstTime;
}
while (!readyQueue.empty() || !jobs.empty()) {
if (!readyQueue.empty()) {
Job currentJob = readyQueue.front();
readyQueue.pop();
if (currentJob.remainingTime > quantum) {
currentTime += quantum;
currentJob.remainingTime -= quantum;
readyQueue.push(currentJob);
} else {
currentTime += currentJob.remainingTime;
currentJob.remainingTime = 0;
int waitingTime = currentTime - currentJob.arrivalTime - currentJob.burstTime;
int turnaroundTime = currentTime - currentJob.arrivalTime;
totalWaitingTime += waitingTime;
totalTurnaroundTime += turnaroundTime;
std::cout << "Job with Arrival Time " << currentJob.arrivalTime << " and Burst Time " << currentJob.burstTime << " completed at Time " << currentTime << std::endl;
std::cout << "Waiting Time: " << waitingTime << std::endl;
std::cout << "Turnaround Time: " << turnaroundTime << std::endl;
}
}
while (!jobs.empty() && jobs.front().arrivalTime <= currentTime) {
readyQueue.push(jobs.front());
jobs.erase(jobs.begin());
}
}
double averageWaitingTime = static_cast<double>(totalWaitingTime) / totalJobs;
double averageTurnaroundTime = static_cast<double>(totalTurnaroundTime) / totalJobs;
std::cout << "Average Waiting Time: " << averageWaitingTime << std::endl;
std::cout << "Average Turnaround Time: " << averageTurnaroundTime << std::endl;
}
int main() {
std::vector<Job> jobs = {
{0, 10}, {1, 4}, {2, 5}, {3, 3}, {4, 8}, {5, 6}, {6, 2}, {7, 7}, {8, 1}, {9, 9},
// Add the remaining 20 jobs here
};
std::vector<int> quantumNumbers = {5, 10, 15, 20, 30, 40};
for (int quantum : quantumNumbers) {
std::cout << "Quantum Number: " << quantum << std::endl;
roundRobinScheduling(jobs, quantum);
std::cout << std::endl;
}
return 0;
}
```
In this program, the `jobs` vector contains the arrival times and burst times of 30 jobs. The program then prompts the user to enter different quantum numbers to calculate the completion time, waiting time, and turnaround time for each quantum number. The average waiting time and average turnaround time are also displayed.
Please note that this code assumes that the arrival times and burst times are predefined and stored in the `jobs` vector. You can modify the code to change the values or read them from a file if needed.