-
Notifications
You must be signed in to change notification settings - Fork 1
/
FCFS.cpp
67 lines (65 loc) · 1.13 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
59
60
61
62
63
64
65
66
67
#include <iostream>
class process
{
public:
int arrtime;
int cbt;
};
int main()
{
process p[20];
int np,atime[20];
cout<<"enter no of process \n";
cin>>np;
cout<<"enter arr time \n";
for(int i=0;i<np;i++)
{
cin>>p[i].arrtime;
}
/*sort arrival time*/
for(i=0;i<np;i++)
{
atime[i]=p[i].arrtime;
}
for(i=0;i<np;i++)
{
for(j=i+1;j<np;j++)
{
if(atime[i]>atime[j])
{
int s=atime[i];
atime[i]=atime[j];
atime[j]=s;
}
}
}
cout<<"enter CBT of processes \n";
for(i=0;i<np;i++)
{
cin>>p[i].cbt;
}
/*print gantt chat*/
int wtime[20];
wtime[0]=0;
cout<<" ";
for(i=0;i<np;i++)
{
for(int j=0;j<p[i].cbt;j++)
{
if(j>=atime[i])
{cout<<"p"<<i<<" ";}
else
{
cout<<"i";
if(j<atime[0])
{wtime[0]++;}
}
}
wtime[i+1]=wtime[i]+p[i].cbt;
}
for(i=0;i<;i++)
{
cout<<i;
}
return 0;
}