Monday, 1 February 2016

C++ Program For (FCFS) FIRST COME FIRST SERVE In Linux Scheduling Algorithm

//Ghanendra Yadav
#include<iostream>
using namespace std;
int main()
{
int p, sum=0;
double awt=0, atat=0;
cout<<"\n ENTER  PROCESS : ";
cin>>p;
int *cbt = new int[p];
int  *wt = new int[p];
int *tat = new int[p];
cout<<"Enter CBT Of Process : ";
for(int i=0; i<p; i++)
cin>>cbt[i];
cout<<"\n Gantt Chart \n";
cout<<"-------------------------------------------------------\n";
for(int i=0; i<p; i++)
cout<<"| "<<'p'<<i+1<<" ";
cout<<endl;
cout<<"-------------------------------------------------------\n";

for(int i=0; i<p; i++)
{
cout<<sum<<"    ";
wt[i]=sum;
sum+=cbt[i];
tat[i]=sum;
}
cout<<endl;
for(int i=0; i<p; i++)
{
awt+=wt[i];
atat+=tat[i];
}
awt=awt/p;
atat=atat/p;
cout<<"\n";
cout<<"\n Process\t CBT\t W.time\t Turn Around Time\n";
for(int i=0; i<p; i++)
cout<<"  p"<<i+1<<"\t"<<cbt[i]<<"\t"<<wt[i]<<"\t"<<tat[i]<<endl;
cout<<"\n Average Awating Time : "<<awt;
cout<<"\n Average Turn Around Time : "<<atat<<endl;

return 0;
}

Output:-


2 comments:
Write comments

Recommended Posts × +