upsidedown

fcfs

Aug 5th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // Program to implement First Come First Serve Algorithm.
  2. #include<iostream>
  3. #include<conio.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int nop, burst[10],arrival[10],i, j, index=0,small;
  10. int tat[10], wt[10], ft[10], p[10], temp, t=0, f=0, w=0;
  11.  
  12.     cout<<"Enter the number of processes: ";
  13.     cin>>nop;
  14.  
  15.     cout<<"\nEnter the Arrival time and burst time for each of these processes:\n\t\tArrival\tBurst\n";
  16.    
  17. for(i=0; i<nop;i++)
  18.     {
  19.         cout<<"Process "<<i<<"\t";
  20.         cin>>arrival[i]>>burst[i];
  21.         p[i]=i;
  22.     }
  23.  
  24.     for(i=0; i<nop-1; i++)
  25.         for(j=0; j<nop-i-1;j++)
  26.             if(arrival[j]>arrival[j+1])
  27.             {
  28.                 temp = arrival[j];
  29.             arrival[j]=arrival[j+1];
  30.             arrival[j+1] = temp;
  31.             temp = burst[j];
  32.             burst[j]=burst[j+1];
  33.                    burst[j+1] = temp;
  34.                 temp = p[j];
  35.                 p[j]=p[j+1];
  36.                 p[j+1]=temp;
  37.             }
  38.    
  39.     for(i=0;i<nop;i++)
  40.     {
  41.         f+=burst[i];
  42.         ft[i]=f;
  43.         tat[i]=ft[i]-arrival[i];
  44.         t+=tat[i];
  45.         wt[i]= tat[i] - burst[i];
  46.         w+=wt[i];
  47.     }
  48.     cout<<"\n\nPROCESS\t\tARRIVAL\tBURST\tFINISH\tTAT\tWAITING\n";
  49.     for(i=0; i<nop;i++)
  50.     {
  51.         cout<<"Process "<<p[i]<<"\t";
  52.         cout<<arrival[i]<<"\t"<<burst[i]<<"\t"<<ft[i]<<"\t"<<tat[i]<<"\t"<<wt[i]<<endl;
  53.     }
  54.     cout<<"\nAverage TAT = "<<(t/float(nop));
  55.     cout<<"\nAverage WT = "<<(w/float(nop));
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment