Write a C++ code/Linux shell script to implement CPU scheduling algorithm Round Robin

Code:

#include<iostream>

using namespace std;

int main()
{
    int bursttimeone[20],varpro[20],varwaiting[20],total[20],pror[20],i,b,num,totalone=0,varspro,tempro,preavg,total_average;
    cout<<"Enter Total number of prorocess:";
    cin>>num;

    cout<<"\numEnter value of Burst Time and proriority\num";
    for(i=0;i<num;i++)
    {
        cout<<"\numpro["<<i+1<<"]\num";
        cout<<"Burst Time:";
        cin>>bursttimeone[i];
        cout<<"proriority:";
        cin>>pror[i];
        varpro[i]=i+1;
    }

    for(i=0;i<num;i++)
    {
        varspro=i;
        for(b=i+1;b<num;b++)
        {
            if(pror[b]<pror[varspro])
                varspro=b;
        }

        tempro=pror[i];
        pror[i]=pror[varspro];
        pror[varspro]=tempro;

        tempro=bursttimeone[i];
        bursttimeone[i]=bursttimeone[varspro];
        bursttimeone[varspro]=tempro;

        tempro=varpro[i];
        varpro[i]=varpro[varspro];
        varpro[varspro]=tempro;
    }

    varwaiting[0]=0;
                    for(i=1;i<num;i++)
    {
        varwaiting[i]=0;
        for(b=0;b<i;b++)
            varwaiting[i]+=bursttimeone[b];

        totalone+=varwaiting[i];
    }

    preavg=totalone/num;
    totalone=0;

    cout<<"\num prorocess\t    Burst Time    \tWaiting Time\tTurnarounment Time";
    for(i=0;i<num;i++)
    {
        total[i]=bursttimeone[i]+varwaiting[i];
        totalone+=total[i];
        cout<<"\numpro["<<varpro[i]<<"]\t\t  "<<bursttimeone[i]<<"\t\t    "<<varwaiting[i]<<"\t\t\t"<<total[i];
    }

    total_average=totalone/num;
    cout<<"Value Of Average Waitinumg Time="<<preavg<<endl;
    cout<<"Value Of Average Turnarounment Time="<<total_average<<endl;

    return 0;
}

Post a Comment

0 Comments