
There's an error in the part that "function" was not declared in the code. Can you fix the code?
Code:
#include <iostream>
#include <queue>
#include <
using namespace std;
struct Process {
int processId;
int burstTime;
int priority;
};
// Function to calculate average waiting time and average turnaround time
void calculateAvgTimes(vector<Process>& processes, vector<int>& waitingTimes, vector<int>& turnaroundTimes) {
int totalProcesses = processes.size();
int totalWaitingTime = 0;
int totalTurnaroundTime = 0;
for (int i = 0; i < totalProcesses; i++) {
totalWaitingTime += waitingTimes[i];
totalTurnaroundTime += turnaroundTimes[i];
}
float avgWaitingTime = (float)totalWaitingTime / totalProcesses;
float avgTurnaroundTime = (float)totalTurnaroundTime / totalProcesses;
cout << "Average Waiting Time: " << avgWaitingTime << endl;
cout << "Average Turnaround Time: " << avgTurnaroundTime << endl;
}
// Function to perform Multilevel Queue Scheduling
void multilevelQueueScheduling(vector<Process>& processes) {
int totalProcesses = processes.size();
// Queues for different levels of scheduling
queue<Process> fcfsQueue;
queue<Process> rrQueue;
priority_queue<Process, vector<Process>, function<bool(const Process&, const Process&)>> priorityQueue(
[](const Process& p1, const Process& p2) { return p1.priority > p2.priority; });
// Splitting the processes into different queues based on priority
for (int i = 0; i < totalProcesses; i++) {
if (processes[i].priority == 1)
fcfsQueue.push(processes[i]);
else if (processes[i].priority == 2)
rrQueue.push(processes[i]);
else if (processes[i].priority == 3)
priorityQueue.push(processes[i]);
}
// Vector to store waiting times and turnaround times
vector<int> waitingTimes(totalProcesses, 0);
vector<int> turnaroundTimes(totalProcesses, 0);
// FCFS Scheduling
int time = 0;
while (!fcfsQueue.empty()) {
Process currentProcess = fcfsQueue.front();
fcfsQueue.pop();
waitingTimes[currentProcess.processId - 1] = time;
time += currentProcess.burstTime;
turnaroundTimes[currentProcess.processId - 1] = time;
}
// RR Scheduling
while (!rrQueue.empty()) {
Process currentProcess = rrQueue.front();
rrQueue.pop();
waitingTimes[currentProcess.processId - 1] = time;
if (currentProcess.burstTime > 2) {
currentProcess.burstTime -= 2;
time += 2;
rrQueue.push(currentProcess);
} else {
time += currentProcess.burstTime;
turnaroundTimes[currentProcess.processId - 1] = time;
}
}
// Priority Scheduling
while (!priorityQueue.empty()) {
Process currentProcess = priorityQueue.top();
priorityQueue.pop();
waitingTimes[currentProcess.processId - 1] = time;
time += currentProcess.burstTime;
turnaroundTimes[currentProcess.processId - 1] = time;
}
// Displaying Gantt Chart
cout << "Gantt Chart:\n";
for (int i = 0; i < totalProcesses; i++) {
cout << "P" << processes[i].processId << "\t";
}
cout << endl;
for (int i = 0; i < totalProcesses; i++) {
cout << waitingTimes[i] << "\t";
}
cout << endl;
calculateAvgTimes(processes, waitingTimes, turnaroundTimes);
}
int main() {
vector<Process> processes = {
{1, 8, 4},
{2, 6, 1},
{3, 1, 2},
{4, 9, 2},
{5, 3, 3}
};
multilevelQueueScheduling(processes);
return 0;
}


Step by stepSolved in 5 steps with 3 images

- C++ Code dynamicarray.h and dynamicarray.cpparrow_forwardneed help in C++ Problem: You are asked to create a program for storing the catalog of movies at a DVD store using functions, files, and user-defined structures. The program should let the user read the movie through the file, add, remove, and output movies to the file. For this assignment, you must store the information about the movies in the catalog using a single vector. The vector's data type is a user-defined structure that you must define on functions.h following these rules: Identifier for the user-define structure: movie. Member variables of the structure "movie": name (string), year (int), and genre (string). Note: you must use the identifiers presented before when defining the user-defined structure. Your solution will NOT pass the unit test cases if you do not follow the instructions presented above. The main function is provided (you need to modify the code of the main function to call the user-defined functions described below). The following user-defined functions are…arrow_forwardMASM x86 classarrow_forward
- Please do it on c++ don't use stl function must read the instructionarrow_forwardAll files are included below, seperated by the dashes. "----" //driver.cpp #include <iostream> #include <string> #include "stackLL.h" #include "queueLL.h" #include "priorityQueueLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLLstk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout<<"Popping: "<<stk.pop() <<endl; cout<<"Popping: "<<stk.pop() <<endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout<<"Popping: "<<stk.pop() <<endl; } // output order: 11,2,23,19,17,3,7,13,5 stackLLstkx; stkx.push(5); stkx.push(10); stkx.push(15); stkx.push(20); stkx.push(25); stkx.push(30); stkx.insertAt(-100, 3); stkx.insertAt(-200, 7); stkx.insertAt(-300, 0); //output order: -300,30,25,20,-100,15,10,5,-200 while( ! stkx.empty() ) cout<<"Popping: "<<stkx.pop() <<endl; ///////////////////////////////////////…arrow_forwardI was given the below code in c++, //used headesr#include<iostream>#include<string>using namespace std; //queueu structstruct queue{ //to store each order data string ord_name; string ord_dsc; float ord_total; float ord_tip; string ord_date; //next and previouse order record queue *next; queue *prev;}; //to hold first node address of linklistqueue *root; //function to check is queu empty or notbool is_Empty(){ if (root == NULL) return true; else return false;} //function to add ordervoid addOrder(){ queue *order = new queue(); cout << "\nName on order: "; cin.ignore(); getline(cin, order->ord_name); cout << "\nOrder description: "; getline(cin, order->ord_dsc); cout << "\nOrder Total (integer): "; cin >> order->ord_total; cout << "\nOrder Tip (integer): "; cin >> order->ord_tip; cout << "\nDate of order: "; cin.ignore(); getline(cin,…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





