-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcfs.cpp
58 lines (56 loc) · 1.02 KB
/
fcfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
int shortest(int at[],int done[],int n)
{
int k=0;
for(int i=0;i<n;i++)
{
if(at[k]>at[i]&&done[i]!=1)
k=i;
else if(at[k]==at[i]&&done[i]!=1)
k=i;
}
return k;
}
int main()
{
int n;
cout<<"enter no of processes :";
cin>>n;
int *bt=new int[n];
cout<<"enter burst times : ";
for(int i=0;i<n;i++)
cin>>bt[i];
cout<<"enter arrival times : ";
int *at=new int[n];
for(int i=0;i<n;i++)
cin>>at[i];
int ct=0;
int *wt=new int[n];
int *tat=new int[n];
cout<<"PID\tAT\tBT\tCT\tWT\tTAT\n";
int p=0;
int *done=new int[n];
for(int i=0;i<n;i++)
done[i]=0;
while(p<n)
{
int i=shortest(at,done,n);
wt[i]=ct-at[i];
ct+=bt[i];
tat[i]=ct-at[i];
cout<<i<<"\t"<<at[i]<<"\t"<<bt[i]<<"\t"<<ct<<"\t"<<wt[i]<<"\t"<<tat[i]<<endl;p++;
at[i]=99999;
done[i]=1;
}
float awt,atat;awt=atat=0.0;
for(int i=0;i<n;i++)
{
awt+=wt[i];
atat+=tat[i];
}
awt=float(awt/n);
atat=float(atat/n);
cout<<"average waiting time: "<<awt<<endl;
cout<<"average turn around time : "<<atat<<endl;
}