-
Notifications
You must be signed in to change notification settings - Fork 1
/
FCFS0.cpp
47 lines (45 loc) · 1.12 KB
/
FCFS0.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout<<"\t\t\t\tFIRST COME FIRST SERVE FOR ZERO ARRIVAL TIME\n";
int n;
cout<<"Enter no. of processes:";
cin>>n; //number of processes in schedular
int BT[n];
cout<<"Enter Burst time:\n";
for(int i=0;i<n;i++) //input BT(Arrival time is 0 for all processes)
{
cin>>BT[i];
}
int CT[n],TAT[n],WT[n];
for(int i=0;i<n;i++)
{
if(i==0)
{
CT[0]=BT[0];
TAT[0]=CT[0];
WT[0]=TAT[0]-BT[0];
}
else
{
CT[i]=CT[i-1]+BT[i]; //calculating completion time
TAT[i]=CT[i]; //calculating Turn around time
WT[i]=TAT[i]-BT[i]; //caculating Wating time
}
}
cout<<"CT TAT WT"<<endl ;
for(int i=0;i<n;i++) //To print value of CT,TAT,WT
{
cout<<CT[i]<<" "<<TAT[i]<<" "<<WT[i]<<endl;
}
float sum1=0,sum2=0;
for(int i=0;i<n;i++) //To find average of TAT,WT
{
sum1=sum1+TAT[i];
sum2=sum2+WT[i];
}
cout<<"Average TAT:"<<sum1/n<<endl;
cout<<"Average WT:"<<sum2/n;
return 0;
}