Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need it in C++ to run it on visual studio. Simulate First Come First Served (F

ID: 3877212 • Letter: I

Question

I need it in C++ to run it on visual studio.

Simulate First Come First Served (FCFS) Scheduling Algorithm

a. In this part of the program, you will:  

· Prompt the user to enter the number of processes (limit to 5)

· Prompt the user to enter the burst time for each process

· Calculate waiting time for each process

· Calculate turnaround time for each process

· Calculate average waiting time and turnaround time for all the processes

Simulate Priority Scheduling Algorithm

a. In this part of the programyou will (just modify your last program):  

• Prompt the user to enter the number of processes (limit to 5)

• Prompt the user to enter the burst time and priority number for each process (1 is the highest)

• Sort the processes in ascending order according to their priorities.

• Calculate waiting time for each process based on the priority list

• Calculate turnaround time for each process based on the priority list

• Calculate average waiting time and turnaround time for all the processes

Explanation / Answer

#include<iostream>

using namespace std;

int main()

{

    int n, burst[5], wait[5], turn[5];

    int i, j, avg_bust = 0, avg_wait = 0, avg_turn = 0;

    cout<<" First Come First Served Scheduling Algorithm";

    cout<<" Enter the number of process: ";

    cin>>n;

    cout<<" Enter the Burst time for each process: ";

    for(i = 0; i < n; i++)

    {

        cout<<" P["<<i + 1<<"]:";

        cin>>burst[i];

    }

    wait[0] = 0;

    for(i = 0; i < n; i++)

    {

        wait[i] = 0;

        for(j = 0; j < i; j++)

            wait[i] = wait[i] + burst[j];

    }

    cout<<" Process Burst Time Waiting Time Turnaround Time";

    for(i = 0; i < n; i++)

    {

        turn[i] = burst[i] + wait[i];

        avg_wait = avg_wait + wait[i];

        avg_turn = avg_turn + turn[i];

        cout<<" P[" <<i + 1 <<"]" <<" " <<burst[i] <<" " <<wait[i] <<" " <<turn[i];

    }

    avg_wait = avg_wait / i;

    avg_turn = avg_turn / i;

    cout<<" Average Waiting Time: " <<avg_wait;

    cout<<" Average Turnaround Time: " <<avg_turn;

    return 0;

}

OUTPUT

First Come First Served Scheduling Algorithm

Enter the number of process: 3

Enter the Burst time for each process:

P[1]:27

P[2]:3

P[3]:2

Process      Burst Time                        Waiting Time              Turnaround Time

P[1]                       27 0 27

P[2]                       3 27 30

P[3]                       2 30 32

Average Waiting Time: 19

Average Turnaround Time: 29

*********************************************************************************************************************************

#include<iostream>

using namespace std;

int main()

{

    int n, proc[3], burst[5], wait[5], turn[5], pri[5];

    int i, j, avg_bust = 0, avg_wait = 0, avg_turn = 0;

    cout<<" Priority Scheduling Algorithm";

    cout<<" Enter the number of process: ";

    cin>>n;

    cout<<" Enter the Burst time and Priority for each process: ";

    for(i = 0; i < n; i++)

    {

        cout<<" P["<<i + 1<<"]:";

        cin>>burst[i];

        cout<<" Pri["<<i + 1<<"]:";

        cin>>pri[i];

    }

    for(i = 0; i < n - 1; i++)

    {

        for(j = i + 1; j < n; j++)

        {

            if(pri[i] < pri[j])

            {

                int temp = pri[i];

                pri[i] = pri[j];

                pri[j] = temp;

                temp = burst[i];

                burst[i] = burst[j];

                burst[j] = temp;

                temp = proc[i];

                proc[i] = proc[j];

                proc[j] = temp;

            }

        }

    }

    wait[0] = 0;

    turn[0] = burst[0];

    avg_turn = turn[0];

    for(i = 1; i < n; i++)

    {

        wait[i] = turn[i - 1];

        avg_wait = avg_wait + wait[i];

        turn[i] = burst[i] + wait[i];

        avg_turn = avg_turn + turn[i];

    }

    cout<<" Process Burst Time Waiting Time Turnaround Time Priority";

    for(i = 0; i < n; i++)

        cout<<" P[" <<i + 1 <<"]" <<" " <<burst[i] <<" " <<wait[i] <<" " <<turn[i] <<" " <<pri[i];

    avg_wait = avg_wait / n;

    avg_turn = avg_turn / n;

    cout<<" Average Waiting Time: " <<avg_wait;

    cout<<" Average Turnaround Time: " <<avg_turn;

    return 0;

}

OUTPUT

Priority Scheduling Algorithm

Enter the number of process: 3

Enter the Burst time and Priority for each process:

P[1]:12

Pri[1]:1

P[2]:7

Pri[2]:3

P[3]:8

Pri[3]:2

Process Burst Time Waiting Time Turnaround Time Priority

P[1]                       7                                              0                                              7 3

P[2]                       8                                              7                                              15 2

P[3]                       12                                           15 27 1

Average Waiting Time: 7

Average Turnaround Time: 16