FIFO in C++

First In First Out(FIFO) is known as first come first served. It is also known as FCFS is the simplest scheduling algorithm.

Below coding is the program for FIFO in C++ how the operation system the job using FIFO method.

//FIFO

#include<iostream.h>
#include<conio.h>
int main()
{
  int jb[20],n,bt[20],i,j,ar[20],fn[20],wt[20],tt[20],twt,awt;
  float aawt,atwt;
  clrscr();
  cout<<"\n\nEnter the no. of JOB: ";
  cin>>n;
  twt=0; tt[0]=0;wt[0]=0;fn[0]=0;ar[0]=0;
  for(i=1;i<=n;i++)
  {
    jb[i]=i;
    cout<<endl<<"\nEnter the arrival time for JOB["<<i<<"]: ";
    cin>>ar[i];
    cout<<"Enter the Burst time for JOB["<<i<<"]: ";
    cin>>fn[i];
  }
  for(i=1;i<n;i++)
  {
   for(j=1;j<n;j++)
   {
    if(ar[j]>ar[j+1])
    {
      twt=ar[j];ar[j]=ar[j+1];ar[j+1]=twt;
      awt=fn[j];fn[j]=fn[j+1];fn[j+1]=awt;
      twt=jb[j];jb[j]=jb[j+1];jb[j+1]=twt;
    }
   }
  }
  for(j=1;j<=n;j++)
  {
    wt[j]=(wt[j-1]+fn[j-1])+(ar[j-1]-ar[j]);
    tt[j]=fn[j]+wt[j];
  }
  cout<<endl<<endl<<endl;
  cout<<"JOB NO\tARRIVAL TIME\tBURST TIME\tWAITING TIME\tTURNAROUND TIME"<<endl;
  cout<<"---------------------------------------------------------------"<<endl;
  awt=0;twt=0;
  for(j=1;j<=n;j++)
  {
    cout<<" "<<jb[j]<<"\t\t"<<ar[j]<<"\t\t"<<fn[j]<<"\t\t"<<wt[j]<<"\t\t"<<tt[j]<<endl;
    awt=awt+wt[j];
    twt=twt+tt[j];
  }
  atwt=twt/n;
  aawt=awt/n;
  cout<<"\n\nTOTAL WAITING TIME IS "<<awt<<"\t\tAVERAGE WAITING TIME IS "<<aawt;
  cout<<"\n\nTOTAL TURNAROUND TIME IS "<<twt<<"\t\tAVERAGE TURNAROUND TIME IS "<<atwt;

 getch();
 return 0;
}

 

Leave a Reply