forked from arjuaman/Hacktoberfest2k21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.cpp
More file actions
49 lines (48 loc) · 762 Bytes
/
Copy pathFCFS.cpp
File metadata and controls
49 lines (48 loc) · 762 Bytes
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
#include<iostream>
using namespace std;
class cpusched
{
int n,bt[20],wt[20],tat[20],twt;
float avg_wt,avg_tat;
public:
void data();
void FCFS();
void SJF();
void Priority();
void RoundR();
};
void cpusched::data()
{
cout<<"\nEnter the total no. of processes:\n";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"\nEnter the burst time for process P"<<i<<":\n";
cin>>bt[i];
}
}
void cpusched::FCFS()
{
twt=0;
for(int i=1;i<=n;i++)
{
cout<<"\nBurst time for process P"<<i<<" is :\n"<<bt[i];
}
wt[1]=0;
for(int i=2;i<=n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
}
for(int i=1;i<=n;i++)
{
twt+=wt[i];
avg_wt=twt/n;
}
cout<<"\n Total waiting time is:\n"<<twt<<"\n Average waiting is:\n"<<avg_wt<<endl;
}
int main()
{
cpusched C;
C.data();
C.FCFS();
}