Can you fix the code of the completion time based on the last execution of each process in the gantt chart and the output of the completion time must be the same as the image below? Code: #include #include #include #include struct Process {     int processId;     int burstTime;     int priority; }; void print_gantt_chart(const std::vector>& gantt_chart) {     std::cout << "Gantt Chart:" << std::endl;     std::cout << "----------------------------------------------------------------------------" << std::endl;     std::cout << "| ";     for (const auto& process : gantt_chart) {         std::cout << "P" << process.first << " | ";     }     std::cout << std::endl;     std::cout << "----------------------------------------------------------------------------" << std::endl;     std::cout << "0  ";     int currentTime = 0;     for (const auto& process : gantt_chart) {         currentTime += process.second;         if (std::to_string(currentTime).length() == 1)             std::cout << "  " << currentTime << "  ";         else             std::cout << "  " << currentTime << " ";     }     std::cout << std::endl; } 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::vector> gantt_chart;     while (!fcfs.empty() || !rr.empty() || !priority.empty()) {         if (!fcfs.empty()) {             Process process = fcfs.front();             fcfs.pop();             int executionTime = std::min(quantumTime, process.burstTime);             process.burstTime -= executionTime;             gantt_chart.emplace_back(process.processId, executionTime);             if (process.burstTime > 0)                 fcfs.push(process);         }         if (!rr.empty()) {             Process process = rr.front();             rr.pop();             int executionTime = std::min(quantumTime, process.burstTime);             process.burstTime -= executionTime;             gantt_chart.emplace_back(process.processId, executionTime);             if (process.burstTime > 0)                 rr.push(process);         }         if (!priority.empty()) {             Process process = priority.front();             priority.pop();             int executionTime = std::min(quantumTime, process.burstTime);             process.burstTime -= executionTime;             gantt_chart.emplace_back(process.processId, executionTime);             if (process.burstTime > 0)                 priority.push(process);         }     }     print_gantt_chart(gantt_chart);     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;         currentEndTime += process.burstTime;         completionTime[processIndex] = currentEndTime;         turnaroundTime[processIndex] = completionTime[processIndex];         waitingTime[processIndex] = turnaroundTime[processIndex] - process.burstTime;     }     std::cout << "\nProcess\t\tBurst Time\t\tPriority\t\tCompletion Time\t\tTurnaround Time\t\tWaiting Time" << std::endl;     for (const auto& process : processes) {         int processIndex = process.processId - 1;         std::cout << "P" << process.processId << "\t\t" << process.burstTime << "\t\t\t" << process.priority << "\t\t\t"             << completionTime[processIndex] << "\t\t\t" << turnaroundTime[processIndex] << "\t\t\t" << waitingTime[processIndex] << 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 << std::endl;     std::cout << "Average Waiting Time: " << avgWaitingTime << std::endl;     std::cout << "Average Turnaround Time: " << avgTurnaroundTime << std::endl; } int main() {     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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

Can you fix the code of the completion time based on the last execution of each process in the gantt chart and the output of the completion time must be the same as the image below?

Code:

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

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

void print_gantt_chart(const std::vector<std::pair<int, int>>& gantt_chart) {
    std::cout << "Gantt Chart:" << std::endl;
    std::cout << "----------------------------------------------------------------------------" << std::endl;
    std::cout << "| ";

    for (const auto& process : gantt_chart) {
        std::cout << "P" << process.first << " | ";
    }

    std::cout << std::endl;
    std::cout << "----------------------------------------------------------------------------" << std::endl;
    std::cout << "0  ";

    int currentTime = 0;
    for (const auto& process : gantt_chart) {
        currentTime += process.second;
        if (std::to_string(currentTime).length() == 1)
            std::cout << "  " << currentTime << "  ";
        else
            std::cout << "  " << currentTime << " ";
    }

    std::cout << std::endl;
}

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::vector<std::pair<int, int>> gantt_chart;

    while (!fcfs.empty() || !rr.empty() || !priority.empty()) {
        if (!fcfs.empty()) {
            Process process = fcfs.front();
            fcfs.pop();

            int executionTime = std::min(quantumTime, process.burstTime);
            process.burstTime -= executionTime;

            gantt_chart.emplace_back(process.processId, executionTime);

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

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

            int executionTime = std::min(quantumTime, process.burstTime);
            process.burstTime -= executionTime;

            gantt_chart.emplace_back(process.processId, executionTime);

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

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

            int executionTime = std::min(quantumTime, process.burstTime);
            process.burstTime -= executionTime;

            gantt_chart.emplace_back(process.processId, executionTime);

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

    print_gantt_chart(gantt_chart);

    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;
        currentEndTime += process.burstTime;
        completionTime[processIndex] = currentEndTime;
        turnaroundTime[processIndex] = completionTime[processIndex];
        waitingTime[processIndex] = turnaroundTime[processIndex] - process.burstTime;
    }

    std::cout << "\nProcess\t\tBurst Time\t\tPriority\t\tCompletion Time\t\tTurnaround Time\t\tWaiting Time" << std::endl;
    for (const auto& process : processes) {
        int processIndex = process.processId - 1;
        std::cout << "P" << process.processId << "\t\t" << process.burstTime << "\t\t\t" << process.priority << "\t\t\t"
            << completionTime[processIndex] << "\t\t\t" << turnaroundTime[processIndex] << "\t\t\t" << waitingTime[processIndex] << 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 << std::endl;
    std::cout << "Average Waiting Time: " << avgWaitingTime << std::endl;
    std::cout << "Average Turnaround Time: " << avgTurnaroundTime << std::endl;
}

int main() {
    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;
}

Gantt Chart
0
P2 P3 PI P2
3
2
P1 =
P2 =
Completion Time
27
13
5 7
1
P3 =
3
P4 = 25
P5: 20
рч
... 4
P5
p2 P4
(13)
PI РЧ P5 рч PI
15 17 19
20) 22
PUT PI
24 25 27
Transcribed Image Text:Gantt Chart 0 P2 P3 PI P2 3 2 P1 = P2 = Completion Time 27 13 5 7 1 P3 = 3 P4 = 25 P5: 20 рч ... 4 P5 p2 P4 (13) PI РЧ P5 рч PI 15 17 19 20) 22 PUT PI 24 25 27
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education