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

Develop a program in C++ that will receive the following input from the keyboard

ID: 3834598 • Letter: D

Question

Develop a program in C++ that will receive the following input from the keyboard:

Total memory size available

Number of processes, the corresponding arrival time (request) and finish time (release) for each process, the size of each process (which should be smaller than the total memory size)

Having these information, assuming all processes are running in a uniprocessor environment, your program should be able to show how the processes are scheduled until completion based on two uniprocessor scheduling namely Shortest Process Next and Round Robin (Q=3). Then your program is required to calculate the turnaround time for each process and the mean of turnaround time and display which of the two algorithm is more efficient. Your program also should be able to show in step by step how much memory will be allocated and remained for each request and release in a Buddy System.

Explanation / Answer

#include<iostream>

using namespace std;

int main()

{

    int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;

    cout<<"Enter Total Number of Process:";

    cin>>n;

    cout<<" Enter Burst Time and Priority ";

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

    {

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

        cout<<"Burst Time:";

        cin>>bt[i];

        cout<<"Priority:";

        cin>>pr[i];

        p[i]=i+1;           //contains process number

    }

    //sorting burst time, priority and process number in ascending order using selection sort

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

    {

        pos=i;

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

        {

            if(pr[j]<pr[pos])

                pos=j;

        }

        temp=pr[i];

        pr[i]=pr[pos];

        pr[pos]=temp;

        temp=bt[i];

        bt[i]=bt[pos];

        bt[pos]=temp;

        temp=p[i];

        p[i]=p[pos];

        p[pos]=temp;

    }

    wt[0]=0;            //waiting time for first process is zero

    //calculate waiting time

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

    {

        wt[i]=0;

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

            wt[i]+=bt[j];

        total+=wt[i];

    }

    avg_wt=total/n;      //average waiting time

    total=0;

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

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

    {

        tat[i]=bt[i]+wt[i];     //calculate turnaround time

        total+=tat[i];

        cout<<" P["<<p[i]<<"]   "<<bt[i]<<"     "<<wt[i]<<" "<<tat[i];

    }

    avg_tat=total/n;     //average turnaround time

    cout<<" Average Waiting Time="<<avg_wt;

    cout<<" Average Turnaround Time="<<avg_tat;

    return 0;

}