Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program to implement First Come First Serve Algorithm.
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int nop, burst[10],arrival[10],i, j, index=0,small;
- int tat[10], wt[10], ft[10], p[10], temp, t=0, f=0, w=0;
- cout<<"Enter the number of processes: ";
- cin>>nop;
- cout<<"\nEnter the Arrival time and burst time for each of these processes:\n\t\tArrival\tBurst\n";
- for(i=0; i<nop;i++)
- {
- cout<<"Process "<<i<<"\t";
- cin>>arrival[i]>>burst[i];
- p[i]=i;
- }
- for(i=0; i<nop-1; i++)
- for(j=0; j<nop-i-1;j++)
- if(arrival[j]>arrival[j+1])
- {
- temp = arrival[j];
- arrival[j]=arrival[j+1];
- arrival[j+1] = temp;
- temp = burst[j];
- burst[j]=burst[j+1];
- burst[j+1] = temp;
- temp = p[j];
- p[j]=p[j+1];
- p[j+1]=temp;
- }
- for(i=0;i<nop;i++)
- {
- f+=burst[i];
- ft[i]=f;
- tat[i]=ft[i]-arrival[i];
- t+=tat[i];
- wt[i]= tat[i] - burst[i];
- w+=wt[i];
- }
- cout<<"\n\nPROCESS\t\tARRIVAL\tBURST\tFINISH\tTAT\tWAITING\n";
- for(i=0; i<nop;i++)
- {
- cout<<"Process "<<p[i]<<"\t";
- cout<<arrival[i]<<"\t"<<burst[i]<<"\t"<<ft[i]<<"\t"<<tat[i]<<"\t"<<wt[i]<<endl;
- }
- cout<<"\nAverage TAT = "<<(t/float(nop));
- cout<<"\nAverage WT = "<<(w/float(nop));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment