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

Create a C++ program that will read in the data about the process in the ready q

ID: 3680091 • Letter: C

Question

Create a C++ program that will read in the data about the process in the ready queue from a text file whose format is given below and compute the CPU Granting Chart and waiting time for each process. The program will implement the Round Robin CPU scheduling algorithm. Instead of 5 processes I want it to be 3 processes. Below is an example of the text file format to be used. You may come up with your own numbers, time quantum and number of processes to make it much easier

Input file

---processes.data---

3 // # of processes

P1, 27 //Process name, CPU burst time

P2, 4

P3, 15

P4, 50

P5, 35

10 //time quantum, take the average if it is -1!

Output:

Time Quantum: 10

Round #1:

P1: 27/17- 0:10

P2: 4/0 - 10:14* (* means it has ended)

P3: 15/5 - 14:24

P4: 50/40 - 24:34

P5: 35/25 - 34:44

Round #2:

P1: 17/7 - 44:55

P3: 5/0 - 54:49*(*means it has ended)

P4: 40/30 - 59:69

P5: 25/15- 69:79

Round #3:

P1: 7/0 - 79:86*(* means it has ended)

P4: 30/ 20 - 86:96

P5:15/5 - 96:106

Round #4:

..

Round #5:

Waiting Times:

For P1: xx.zz

For P2: aa.dd

For P3: ss.pp

For P4: hh.ff

For P5: kk.cc

Explanation / Answer

#include<iostream.h>

#include<conio.h>

struct processhere

{

    int no;

    int at,

int ext;//execution time

int wt;//waiting time

int tot;//totaltme

    int tet;//total execution time

    int t;

};

void main()

{ int numberprocess;

    processhere p[100];

    int i,j,k;

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

    

    cin>>numberprocess;// we will input 3 for 3 processes

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

    {

        cout<<" Please Enter Execution time of process"<<i+1<<":";

        cin>>p[i].ext;

        p[i].tet=p[i].ext;

        p[i].at=p[i].t=p[i].tot=p[i].wt=0;

        p[i].no=i+1;

    }

    cout<<" Enter Time Quantum:";

    int q;

    cin>>q;

    cout<<" Entered Data";

    cout<<" Process ET";

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

    {

        cout<<" "<<p[i].no<<" "<<p[i].ext;

    }

    int totaltime=0;

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

    {

        totaltime+=p[i].ext;

    }

    i=0;

    k=0;

    int rrg[99];

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

    {

        if((k==0)&&(p[i].ext!=0))

        {

            p[i].wt=j;

            if((p[i].t!=0))

            {

                p[i].wt-=q*p[i].t;

            }

        }

        if((p[i].ext!=0)&&(k!=q))

        {

            rrg[j]=p[i].no;

            p[i].ext-=1;

            k++;

        }

        else

        {

            if((k==q)&&(p[i].ext!=0))

            {

                p[i].t+=1;

            }

            i=i+1;

            if(i==numberprocess)

            {

                i=0;

            }

                k=0;

            j=j-1;

        }

    }

    /*

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

    {

        cout<<" "<<rrg[j];

    }

    */

    int twt=0;//total waiting time

    int ttt=0;//total turnaround tme

    cout<<" Result Of Round Robin";

    cout<<" PNo ET WT TT";

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

    {

        p[i].tot=p[i].wt+p[i].tet;

        ttt+=p[i].tot;

        twt+=p[i].wt;

        cout<<" "<<p[i].no<<" "<<" "<<p[i].tet<<" "<<p[i].wt<<" "<<p[i].tot;

    }

    cout<<" Average Waiting Time for process:"<<(float)twt/numberprocess;

    cout<<" Average Turn Around Time for process:"<<(float)ttt/numberprocess;

    getch();

}