Putting the given in the Priority in the table Putting the values of the Gantt Chart below the Chart Fix the formula of the Completion Time base on the Gantt Chart Code: #include #include #include struct Process {     int processId;     int burstTime;     int priority; }; void multiLevelQueueScheduling(const std::vector& processes, int quantumTime) {     std::queue fcfs;     std::queue rr;     std::queue priority;     for (const auto& process : processes) {         if (process.priority == 1)             fcfs.push(process);         else if (process.priority == 2)             rr.push(process);         else if (process.priority == 3 || process.priority == 4)             priority.push(process);     }     std::cout << "Gantt Chart:\n";     std::cout << "-------------\n";     int totalTime = 0;     while (!fcfs.empty()) {         Process process = fcfs.front();         fcfs.pop();         std::cout << "| P" << process.processId << " ";         int executionTime = std::min(quantumTime, process.burstTime);         process.burstTime -= executionTime;         totalTime += executionTime;         std::cout << " - " << totalTime << " ";         if (process.burstTime > 0)             fcfs.push(process);     }     while (!rr.empty()) {         Process process = rr.front();         rr.pop();         std::cout << "| P" << process.processId << " ";         int executionTime = std::min(quantumTime, process.burstTime);         process.burstTime -= executionTime;         totalTime += executionTime;         std::cout << " - " << totalTime << " ";         if (process.burstTime > 0)             rr.push(process);     }     while (!priority.empty()) {         Process process = priority.front();         priority.pop();         std::cout << "| P" << process.processId << " ";         int executionTime = std::min(quantumTime, process.burstTime);         process.burstTime -= executionTime;         totalTime += executionTime;         std::cout << " - " << totalTime << " ";         if (process.burstTime > 0)             priority.push(process);     }     std::cout << "|\n";     std::cout << "-------------\n\n";     std::vector completionTime(processes.size());     std::vector turnaroundTime(processes.size());     std::vector waitingTime(processes.size());     int currentEndTime = 0;     for (const auto& process : processes) {         int processIndex = process.processId - 1;         completionTime[processIndex] = currentEndTime + process.burstTime;         turnaroundTime[processIndex] = completionTime[processIndex];         waitingTime[processIndex] = turnaroundTime[processIndex] - process.burstTime;         currentEndTime += process.burstTime;     }     //  table sa output     std::cout << "Process\tBurst Time\tCompletion Time\tTurnaround Time\tWaiting Time\n";     for (const auto& process : processes) {         int processIndex = process.processId - 1;         std::cout << "P" << process.processId << "\t"             << process.burstTime << "\t\t"             << completionTime[processIndex] << "\t\t"             << turnaroundTime[processIndex] << "\t\t"             << waitingTime[processIndex] << std::endl;     }     std::cout << std::endl;     float avgWaitingTime = 0;     float avgTurnaroundTime = 0;     for (const auto& process : processes) {         avgWaitingTime += waitingTime[process.processId - 1];         avgTurnaroundTime += turnaroundTime[process.processId - 1];     }     avgWaitingTime /= processes.size();     avgTurnaroundTime /= processes.size();     std::cout << "Average Waiting Time: " << avgWaitingTime << std::endl;     std::cout << "Average Turnaround Time: " << avgTurnaroundTime << std::endl; } int main() {     // process      std::vector processes = {         {1, 8, 4},         {2, 6, 1},         {3, 1, 2},         {4, 9, 2},         {5, 3, 3}     };     int quantumTime = 2;     multiLevelQueueScheduling(processes, quantumTime);     return 0;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Can you fix the code below?

  • Putting the given in the Priority in the table
  • Putting the values of the Gantt Chart below the Chart
  • Fix the formula of the Completion Time base on the Gantt Chart

Code:

#include <iostream>
#include <queue>
#include <vector>

struct Process {
    int processId;
    int burstTime;
    int priority;
};

void multiLevelQueueScheduling(const std::vector<Process>& processes, int quantumTime) {
    std::queue<Process> fcfs;
    std::queue<Process> rr;
    std::queue<Process> priority;


    for (const auto& process : processes) {
        if (process.priority == 1)
            fcfs.push(process);
        else if (process.priority == 2)
            rr.push(process);
        else if (process.priority == 3 || process.priority == 4)
            priority.push(process);
    }


    std::cout << "Gantt Chart:\n";
    std::cout << "-------------\n";
    int totalTime = 0;


    while (!fcfs.empty()) {
        Process process = fcfs.front();
        fcfs.pop();

        std::cout << "| P" << process.processId << " ";
        int executionTime = std::min(quantumTime, process.burstTime);
        process.burstTime -= executionTime;
        totalTime += executionTime;
        std::cout << " - " << totalTime << " ";

        if (process.burstTime > 0)
            fcfs.push(process);
    }


    while (!rr.empty()) {
        Process process = rr.front();
        rr.pop();

        std::cout << "| P" << process.processId << " ";
        int executionTime = std::min(quantumTime, process.burstTime);
        process.burstTime -= executionTime;
        totalTime += executionTime;
        std::cout << " - " << totalTime << " ";

        if (process.burstTime > 0)
            rr.push(process);
    }


    while (!priority.empty()) {
        Process process = priority.front();
        priority.pop();

        std::cout << "| P" << process.processId << " ";
        int executionTime = std::min(quantumTime, process.burstTime);
        process.burstTime -= executionTime;
        totalTime += executionTime;
        std::cout << " - " << totalTime << " ";

        if (process.burstTime > 0)
            priority.push(process);
    }

    std::cout << "|\n";
    std::cout << "-------------\n\n";


    std::vector<int> completionTime(processes.size());
    std::vector<int> turnaroundTime(processes.size());
    std::vector<int> waitingTime(processes.size());

    int currentEndTime = 0;
    for (const auto& process : processes) {
        int processIndex = process.processId - 1;
        completionTime[processIndex] = currentEndTime + process.burstTime;
        turnaroundTime[processIndex] = completionTime[processIndex];
        waitingTime[processIndex] = turnaroundTime[processIndex] - process.burstTime;
        currentEndTime += process.burstTime;
    }

    //  table sa output
    std::cout << "Process\tBurst Time\tCompletion Time\tTurnaround Time\tWaiting Time\n";
    for (const auto& process : processes) {
        int processIndex = process.processId - 1;
        std::cout << "P" << process.processId << "\t"
            << process.burstTime << "\t\t"
            << completionTime[processIndex] << "\t\t"
            << turnaroundTime[processIndex] << "\t\t"
            << waitingTime[processIndex] << std::endl;
    }

    std::cout << std::endl;


    float avgWaitingTime = 0;
    float avgTurnaroundTime = 0;
    for (const auto& process : processes) {
        avgWaitingTime += waitingTime[process.processId - 1];
        avgTurnaroundTime += turnaroundTime[process.processId - 1];
    }

    avgWaitingTime /= processes.size();
    avgTurnaroundTime /= processes.size();


    std::cout << "Average Waiting Time: " << avgWaitingTime << std::endl;
    std::cout << "Average Turnaround Time: " << avgTurnaroundTime << std::endl;
}

int main() {
    // process 
    std::vector<Process> processes = {
        {1, 8, 4},
        {2, 6, 1},
        {3, 1, 2},
        {4, 9, 2},
        {5, 3, 3}
    };


    int quantumTime = 2;


    multiLevelQueueScheduling(processes, quantumTime);

    return 0;
}

Process
P1
P2
P3
P4
P5
Burst Time (ms)
8
6
1
9
3
Priority
4
1
2
2
3
Transcribed Image Text:Process P1 P2 P3 P4 P5 Burst Time (ms) 8 6 1 9 3 Priority 4 1 2 2 3
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY