Can you fix the following parts of the code in the Multilevel queue scheduling?   Parts: //FCFS Scheduling //RR Scheduling with Time Quantum = 2 //Priority Scheduling Output of the values of Gantt Chart   The provided code is in below and the output of the whole code must be the same on the answer on the image below thank you and don't reject it :( 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;     // Splitting the processes into different queues based on 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()) {                  // FCFS Scheduling         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);         }         // RR Scheduling         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);         }         // Priority Scheduling         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 : 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\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; }

icon
Related questions
Question
Can you fix the following parts of the code in the Multilevel queue scheduling?
 
Parts:
  • //FCFS Scheduling
  • //RR Scheduling with Time Quantum = 2
  • //Priority Scheduling
  • Output of the values of Gantt Chart

 

The provided code is in below and the output of the whole code must be the same on the answer on the image below thank you and don't reject it :(


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;

    // Splitting the processes into different queues based on 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()) {
        
        // FCFS Scheduling
        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);
        }

        // RR Scheduling
        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);
        }

        // Priority Scheduling
        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 : 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\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;
}

completion Time
P1 = 27
P2 = 6
P3 = 7
рз
P4 = 16
P5 : 19
Turnaround time
Formula: TAT = CT - AT
PI
27-0=27
P2 =
P3 =
7-0 = 7
P4 = 16 -0 = 16
P5 : 19-0:19
waiting Time
Formula: WT = TAT - BT
P1 = 27 - 8 = 19
P2 =
6 -6
6-6=0
P3 =
7-1=6
РЧ
16-9 = 7
19-3 = 16
我
6-0=6
P5
p5 =
b. Average waiting time
Average waiting time:
19 + 0 + 6 + 7 +16
5
48
5
Average waiting Time = 9.6 ms
c. Average Turnaround time
Average Turnaround time = 27+ 6 + 7 +16 +19
5
75
5
Average turnaround time = 15 ms
Transcribed Image Text:completion Time P1 = 27 P2 = 6 P3 = 7 рз P4 = 16 P5 : 19 Turnaround time Formula: TAT = CT - AT PI 27-0=27 P2 = P3 = 7-0 = 7 P4 = 16 -0 = 16 P5 : 19-0:19 waiting Time Formula: WT = TAT - BT P1 = 27 - 8 = 19 P2 = 6 -6 6-6=0 P3 = 7-1=6 РЧ 16-9 = 7 19-3 = 16 我 6-0=6 P5 p5 = b. Average waiting time Average waiting time: 19 + 0 + 6 + 7 +16 5 48 5 Average waiting Time = 9.6 ms c. Average Turnaround time Average Turnaround time = 27+ 6 + 7 +16 +19 5 75 5 Average turnaround time = 15 ms
Multi-level queue (FCFS. RR, Priority)
Time Quantum = 2
Process Burst Time (ms) Priority
PI
P2
P3
рч
P5
a- Gantt chart
0
P2
6
0
0
P3
P2
8
P2
6
6
|
q
3
4
P3
1
2
Explanation:
FCFS First Priority / High priority
RR - second priority / medium Priority
priority - Third priority / Low priority
P4 P4 рч І ру РЧ
7 9 11
18 15
P4
7 q
2
3
Completion Time
16
a. P2= Highest priority (FCFS) with Burst Time of 6
P4 P4 P4
| | Pч
6
P3 = 1 ×
P4 = 9-2= 7 - 2 = 5-2= 3-2 = 1 ×
a
11 13 15 16
рч
P5
=
C. P5 and PL Low Priority (priority)
b. P3 and Py = Second Priority (RR with Time Quantum= 2)
19
рч
27
6
1
16
P2 P3 рч P4
P4
O 6 ។ 9
11 13 15
16
Priority 3: P5 with Burst Time of 3
=
P5 = 16 13 (19)
Priority 4: PI with Burst Time of 8
PL. = 19. + 8 (27
19
PI
27
P5 PL
Turnaround Time
19 27
27
6
។
16
19
waiting time
19
O
6
។
16
Priority 1: P2 (FCFS)
Priority 2: P3 and P4 (RR with Time Quantum = 2)
priority 3: P5 (priority)
priority 4: PI (priority)
Transcribed Image Text:Multi-level queue (FCFS. RR, Priority) Time Quantum = 2 Process Burst Time (ms) Priority PI P2 P3 рч P5 a- Gantt chart 0 P2 6 0 0 P3 P2 8 P2 6 6 | q 3 4 P3 1 2 Explanation: FCFS First Priority / High priority RR - second priority / medium Priority priority - Third priority / Low priority P4 P4 рч І ру РЧ 7 9 11 18 15 P4 7 q 2 3 Completion Time 16 a. P2= Highest priority (FCFS) with Burst Time of 6 P4 P4 P4 | | Pч 6 P3 = 1 × P4 = 9-2= 7 - 2 = 5-2= 3-2 = 1 × a 11 13 15 16 рч P5 = C. P5 and PL Low Priority (priority) b. P3 and Py = Second Priority (RR with Time Quantum= 2) 19 рч 27 6 1 16 P2 P3 рч P4 P4 O 6 ។ 9 11 13 15 16 Priority 3: P5 with Burst Time of 3 = P5 = 16 13 (19) Priority 4: PI with Burst Time of 8 PL. = 19. + 8 (27 19 PI 27 P5 PL Turnaround Time 19 27 27 6 ។ 16 19 waiting time 19 O 6 ។ 16 Priority 1: P2 (FCFS) Priority 2: P3 and P4 (RR with Time Quantum = 2) priority 3: P5 (priority) priority 4: PI (priority)
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer