Monday, 1 February 2016

C++ Program For (SJF) SHORTEST JOB FIRST Scheduling Algorithm In Linux

//Ghanendra Yadav
#include<iostream>
using namespace std;
int main()
{
int p, sum=0, min, index;
        double awt=0, atat=0;
        cout<<"\nEnter process : ";
        cin>>p;
        int *cbt = new int[p];
        int  *wt = new int[p];
int  *gc = new int[p];
        int *tat = new int[p];
int *tmp = new int[p];
        cout<<"Enter CBT of process : ";
        for(int i=0; i<p; i++)
        {        cin>>cbt[i];
tmp[i]=cbt[i];
}

        cout<<"\nGrant Chart\n";
        cout<<"-------------------------------------------------------\n";
for(int j=0; j<=p; j++)
{
min=100;
for(int i=0; i<p; i++)
{
if(min>tmp[i]&&tmp[i]!=-1)
{ min=tmp[i];
index=i;
}
}
gc[j]=sum;
wt[j]=sum;
sum+=tmp[index];
tat[j]=sum;
tmp[index]=-1;
if(j==p)
break;
                cout<<"| "<<'p'<<index+1<<" |";
}
        cout<<endl;
        cout<<"-------------------------------------------------------\n";
sum=0;
for(int j=0; j<=p; j++)
{
if(gc[j]<10)
cout<<0;
cout<<gc[j]<<"   ";
sum+=gc[j];
}
cout<<endl;
        awt=awt/p;
        atat=atat/p;
        cout<<"\n";
        cout<<"\nprocess\tCBT\tW.time\tturn around time\n";
        for(int i=0; i<p; i++)
                cout<<"  p"<<i+1<<"\t"<<cbt[i]<<"\t"<<wt[i]<<"\t"<<tat[i]<<endl;

}

Output:-


1 comment:
Write comments
  1. Thanks For Helping In This Code

    ReplyDelete

Recommended Posts × +