Can you make C++ code of a Multi-level queue (FCFS, Round Robin, and Priority) for a better understanding of the topic? The explanation of how to make it and the output must be in the image below thank you!

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
Question

Can you make C++ code of a Multi-level queue (FCFS, Round Robin, and Priority) for a better understanding of the topic? The explanation of how to make it and the output must be in the image below thank you! 

Create a C++ program of Multi-level queue scheduling (FCFS, RR, and Priority) that would compute for the:
a. Gantt Chart
b. Average Waiting Time
c. Average Turnaround Time
.
Process
P1
P2
P3
P4
P5
Burst Time (ms)
8
8
6
1
9
3
Priority
4
1
2
2
3
Priority 1 is FCFS Scheduling
Priority 2 is Round Robin with Time Quantum = 2
Priority 3 is Priority Scheduling
Assume
that the process with Priority 1 has highest priority and 4 as low priority.
Show how to solve completely of the three scheduling of all process in one Gantt Chart.
Completion Time must be based on the last execution of each process in Gantt Chart.
The formula for Turnaround Time is Turnaround Time = Completion Time - Arrival Time
The formula for Waiting Time is Waiting Time = Turnaround Time - Burst Time
The last execution of process must end in 27.
Show the values of Gantt Chart and the output must be like this:
cantt Chart
P2 P3 P4 P4 P4 P4 P4 P5 PI
0 6 7 9 11
13
15 16 19 27
Display already in the code of the values of Process, Burst Time (ms), and Priority.
Show the values of Process, Burst Time (ms), Priority, Completion Time, Turnaround Time, and
Waiting Time in table form and the output must be the same in the image on next page:
Process
PI
P2
P3
рч
P5
Burst Time (ms) Priority
4.
8
6
1
9
3
1
2
2
3
Completion Time
27
6
1
16
19
Turnaround Time.
27
6
7
16
19
waiting time
The answer for Average Waiting Time is Average Waiting Time = 9.6ms
The answer for Average Turnaround Time is Average Turnaround Time = 15ms
19
0
6
7
16
Transcribed Image Text:Create a C++ program of Multi-level queue scheduling (FCFS, RR, and Priority) that would compute for the: a. Gantt Chart b. Average Waiting Time c. Average Turnaround Time . Process P1 P2 P3 P4 P5 Burst Time (ms) 8 8 6 1 9 3 Priority 4 1 2 2 3 Priority 1 is FCFS Scheduling Priority 2 is Round Robin with Time Quantum = 2 Priority 3 is Priority Scheduling Assume that the process with Priority 1 has highest priority and 4 as low priority. Show how to solve completely of the three scheduling of all process in one Gantt Chart. Completion Time must be based on the last execution of each process in Gantt Chart. The formula for Turnaround Time is Turnaround Time = Completion Time - Arrival Time The formula for Waiting Time is Waiting Time = Turnaround Time - Burst Time The last execution of process must end in 27. Show the values of Gantt Chart and the output must be like this: cantt Chart P2 P3 P4 P4 P4 P4 P4 P5 PI 0 6 7 9 11 13 15 16 19 27 Display already in the code of the values of Process, Burst Time (ms), and Priority. Show the values of Process, Burst Time (ms), Priority, Completion Time, Turnaround Time, and Waiting Time in table form and the output must be the same in the image on next page: Process PI P2 P3 рч P5 Burst Time (ms) Priority 4. 8 6 1 9 3 1 2 2 3 Completion Time 27 6 1 16 19 Turnaround Time. 27 6 7 16 19 waiting time The answer for Average Waiting Time is Average Waiting Time = 9.6ms The answer for Average Turnaround Time is Average Turnaround Time = 15ms 19 0 6 7 16
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Can you put the Average Waiting Time and Turnaround Time in the code? Thank you!

Code:

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

struct Process {
    int arrivalTime; // Added arrivalTime
    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 fcfsScheduling(std::queue<Process>& fcfsQueue, std::vector<std::pair<int, int>>& gantt_chart) {
    while (!fcfsQueue.empty()) {
        Process process = fcfsQueue.front();
        fcfsQueue.pop();

        int executionTime = process.burstTime;
        gantt_chart.emplace_back(process.processId, executionTime);
    }
}

void rrScheduling(std::queue<Process>& rrQueue, std::vector<std::pair<int, int>>& gantt_chart, int quantumTime) {
    while (!rrQueue.empty()) {
        Process process = rrQueue.front();
        rrQueue.pop();

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

        gantt_chart.emplace_back(process.processId, executionTime);

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

void priorityScheduling(std::queue<Process>& priorityQueue, std::vector<std::pair<int, int>>& gantt_chart) {
    std::priority_queue<Process, std::vector<Process>, std::function<bool(Process, Process)>> pq(
        [](const Process& p1, const Process& p2) { return p1.priority > p2.priority; }
    );

    while (!priorityQueue.empty()) {
        pq.push(priorityQueue.front());
        priorityQueue.pop();
    }

    while (!pq.empty()) {
        Process process = pq.top();
        pq.pop();

        int executionTime = process.burstTime;
        gantt_chart.emplace_back(process.processId, executionTime);
    }
}

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;

    fcfsScheduling(fcfs, gantt_chart);
    rrScheduling(rr, gantt_chart, quantumTime);
    priorityScheduling(priority, gantt_chart);

    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 : gantt_chart) {
        int processIndex = process.first - 1;
        currentEndTime += process.second;
        completionTime[processIndex] = currentEndTime;
        turnaroundTime[processIndex] = completionTime[processIndex];
        waitingTime[processIndex] = turnaroundTime[processIndex] - processes[processIndex].burstTime;
    }

    std::cout << "\nProcess\t\tArrival Time\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.arrivalTime << "\t\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;
    }
}

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

    int quantumTime = 2;

    multiLevelQueueScheduling(processes, quantumTime);

    return 0;
}

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

Can you put Arrival time in the code if all the arrival time in all processes is 0? Thank you!

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

Can you align properly the values of Gantt Chart? Thank you!

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Structured English
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