-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.cpp
More file actions
174 lines (155 loc) · 2.27 KB
/
Copy pathFCFS.cpp
File metadata and controls
174 lines (155 loc) · 2.27 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include<iostream>
using namespace std;
class Gnatt
{
int BT,arr,TAT,WT,RT,pos,org;
public:
void Enter(int i)
{
cout<<"\n Enter Burst time :";
cin>>BT;
cout<<"\n Enter Arrival Time :";
cin>>arr;
org=i;
}
int retOrg()
{
return org;
}
int retArr()
{
return arr;
}
int retPos()
{
return pos;
}
int retBT()
{
return BT;
}
void setP(int i)
{
pos=i;
}
int retTAT()
{
return TAT;
}
int retRT()
{
return RT;
}
int retWT()
{
return WT;
}
int addBT(Gnatt[],int);
void ResT();
void WaitT(Gnatt []);
void Total();
float AvgRT(Gnatt [],int);
float AvgWT(Gnatt [],int);
float AvgTAT(Gnatt [],int);
};
//Waiting Time
void Gnatt::WaitT(Gnatt G[])
{
WT=addBT(G,pos)-arr;
ResT();
}
//Response Time
void Gnatt::ResT()
{
RT=WT;
}
//Turn around Time
void Gnatt::Total()
{
TAT=WT+BT;
}
//Average TAT
float Gnatt::AvgTAT(Gnatt G[],int n)
{
float avg=0;
for(int i=0;i<n;i++)
{
avg+=G[i].TAT;
}
return(avg/n);
}
//Average Waiting Time
float Gnatt::AvgWT(Gnatt G[],int n)
{
float avg=0;
for(int i=0;i<n;i++)
{
avg+=G[i].WT;
}
return(avg/n);
}
//Average Response Time
float Gnatt::AvgRT(Gnatt G[],int n)
{
float avg=0;
for(int i=0;i<n;i++)
{
avg+=G[i].RT;
}
return(avg/n);
}
void Arrange(Gnatt G[],int n)
{
Gnatt T;
int i,j,p;
for(i=0;i<n;i++)
{
for(j=0;j<n-1-i;j++)
{
if(G[j].retArr()>G[j+1].retArr())
{
T=G[j];
G[j]=G[j+1];
G[j+1]=T;
}
}
}
for(i=0;i<n;i++)
{
G[i].setP(i);
}
}
//Add Burst Time
int Gnatt::addBT(Gnatt G[],int index)
{ int s=0,i;
for(i=0;i<index;i++)
{
s+=G[i].retBT();
}
return s;
}
int main()
{
Gnatt G[10],ob;
int n;
cout<<"\n Enter the Number of Processes :";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n Enter Values for Process"<<i+1<<" : ";
G[i].Enter(i+1);
}
//Arrange in the order of Arrival time
Arrange(G,n);
cout<<"\n Result is :";
cout<<"\n \tTAT\tRT\tWT";
for(int i=0;i<n;i++)
{
G[i].WaitT(G);
G[i].ResT();
G[i].Total();
cout<<"\nP"<<G[i].retOrg()<<" \t"<<G[i].retTAT()<<"\t"<<G[i].retWT()<<"\t"<<G[i].retRT();
}
cout<<"\n\nAVG.\t"<<ob.AvgTAT(G,n)<<"\t"<<ob.AvgWT(G,n)<<"\t"<<ob.AvgRT(G,n)<<"\n";
return 0;
}