Write a C++ code/shell script to implement Priority scheduling algorithm

Code:

#include<iostream>

using namespace std;

int main()
{
    int timebirstone[20],varpro[20],waiting[20],total[20],varprof[20],i,b,number,totalfisrt=0,numpro,tempro,avg_wait,total_average;
    cout<<"Enter The Value Of Total numumber of prorocess:";
    cin>>number;

    cout<<"\numEnter Burst Time value proriority\number";
    for(i=0;i<number;i++)
    {
        cout<<"\numpro["<<i+1<<"]\number";
        cout<<"The Burst Time:";
        cin>>timebirstone[i];
        cout<<"The Proriority:";
        cin>>varprof[i];
        varpro[i]=i+1;
    }

    for(i=0;i<number;i++)
    {
        numpro=i;
        for(b=i+1;b<number;b++)
        {
            if(varprof[b]<varprof[numpro])
                numpro=b;
        }

        tempro=varprof[i];
        varprof[i]=varprof[numpro];
        varprof[numpro]=tempro;

        tempro=timebirstone[i];
        timebirstone[i]=timebirstone[numpro];
        timebirstone[numpro]=tempro;

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

    waiting[0]=0;

    for(i=1;i<number;i++)
    {
        waiting[i]=0;
        for(b=0;b<i;b++)
            waiting[i]+=timebirstone[b];

        totalfisrt+=waiting[i];
    }

    avg_wait=totalfisrt/number;
    totalfisrt=0;

    cout<<"\number prorocess\t    Burst Time    \tWaiting Time\tTurnarounament Time";
    for(i=0;i<number;i++)
    {
        total[i]=timebirstone[i]+waiting[i];
        totalfisrt+=total[i];
        cout<<"\numpro["<<varpro[i]<<"]\t\t  "<<timebirstone[i]<<"\t\t    "<<waiting[i]<<"\t\t\t"<<total[i];
    }

    total_average=totalfisrt/number;
    cout<<"Value Of Average Waitinumg Time="<<avg_wait<<endl;
    cout<<"Value Of average Turnarounament Time="<<total_average<endl;

    return 0;
}

Post a Comment

0 Comments