-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcfs.cpp
More file actions
106 lines (94 loc) · 3.1 KB
/
Copy pathfcfs.cpp
File metadata and controls
106 lines (94 loc) · 3.1 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
#include<bits/stdc++.h>
using namespace std;
struct type_a
{
string p;
int w;
int b;
};
struct type_b
{
string p;
int w;
};
bool cmp(type_a A,type_a B)
{
return A.w<B.w;
}
int main()
{
type_a node;
type_b node1;
printf("How many times ? ");
int t;
while(scanf("%d",&t)==1)
{
for(int g=0;g<t;g++)
{
vector<type_a> fc, gantt;
vector<type_b>wait, turn;
double awt=0,trnt=0;
printf("How many process ? : ");
int pn; scanf("%d",&pn);
int w,b;
string pid;
// inputting the necessary datas
for(int i=0;i<pn;i++)
{
printf("Enter process Id , Arrival time , Burst time : ");
cin>>pid>>w>>b;
node.p=pid;
node.w=w;
node.b=b;
fc.push_back(node);
} // End of Inputting datas
cout<<"\nEnd of Input : "<<endl;
cout<<"*******************\n"<<endl;
//std:: vector<type_a>::iterator it;
sort(fc.begin(),fc.end(),cmp); // sorting the Process based on Arrival time
// Printing the Process
for(int i=0;i<pn;i++)
{
cout<<"id : "<< fc[i].p<<", arrival time : "<<fc[i].w << ", Burst Time : "<<fc[i].b<<endl;
}
// end of Printing
int ager=fc[0].w;
for(int i=0;i<pn;i++)
{
node.p=fc[i].p;
node.w=ager;
node.b=ager=node.w+fc[i].b;
gantt.push_back(node);
// Making the Waiting
node1.p=gantt[i].p;
node1.w=gantt[i].w-fc[i].w;
awt=awt+node1.w;
wait.push_back(node1);
// Making the Turnaround
node1.p=gantt[i].p;
node1.w=gantt[i].b-gantt[i].w;
turn.push_back(node1);
trnt=trnt+node1.w;
}
cout<<"\nPrinting The gantt chart : "<<endl;
cout<<"****************************\n"<<endl;
for(int i=0;i<pn;i++)
{
cout<<"id : "<< gantt[i].p<<", visit time : "<<gantt[i].w << ", finish time : "<<gantt[i].b<<endl;
}
awt=awt/pn;
trnt=trnt/pn;
cout<<"\nPrinting Waiting and Turnaround time : "<<endl;
cout<<"******************************************\n"<<endl;
for(int i=0;i<pn;i++)
{
cout<<"id : "<< wait[i].p<<", Waiting time : "<< wait[i].w<< ", Turnaround time : "<< turn[i].w<<endl;
}
cout<<"********************************************************\n"<<endl;
cout<<"The avergae Waiting time is : "<<awt<<endl;
cout<<"The avergae Turnaround time is : "<<trnt<<endl;
cout<<"********************************************************\n"<<endl;
}
}
return 0;
}