Here's an example of a Round Robin scheduling algorithm implemented in C++:
```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;
totalWaitingTime += currentTime - currentJob.arrivalTime - currentJob.burstTime;
totalTurnaroundTime += currentTime - currentJob.arrivalTime;
}
}
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
};
int quantum;
std::cout << "Enter quantum number: ";
std::cin >> quantum;
roundRobinScheduling(jobs, quantum);
return 0;
}
```
In this example, we have a struct `Job` that represents a job with its arrival time and burst time. The `roundRobinScheduling` function implements the Round Robin algorithm, taking the jobs vector and the quantum as input.
You can modify the code to save the 30 arrival times and burst times directly in the `jobs` vector. After executing the algorithm, it will calculate and display the average waiting time and average turnaround time.
Please note that this is just a basic example, and you may need to modify it further based on your specific requirements.