-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFCFS_Variable_Arrival_Time.cpp
More file actions
78 lines (63 loc) · 2.18 KB
/
FCFS_Variable_Arrival_Time.cpp
File metadata and controls
78 lines (63 loc) · 2.18 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
#include<iostream>
using namespace std;
void findWaitingTime(int processes[], int n, int bt[], int wt[], int at[])
{
int service_time[n];
service_time[0] = at[0];
wt[0] = 0;
for (int i = 1; i < n ; i++)
{
service_time[i] = service_time[i-1] + bt[i-1];
wt[i] = service_time[i] - at[i];
if (wt[i] < 0)
wt[i] = 0;
}
}
void findTurnAroundTime(int processes[], int n, int bt[], int wt[], int tat[])
{
for (int i = 0; i < n ; i++)
tat[i] = bt[i] + wt[i];
}
void findavgTime(int processes[], int n, int bt[], int at[])
{
int wt[n], tat[n];
findWaitingTime(processes, n, bt, wt, at);
findTurnAroundTime(processes, n, bt, wt, tat);
cout << "Processes " << " Burst Time " << " Arrival Time " << " Waiting Time " << " Turn-Around Time " << " Completion Time \n";
int total_wt = 0, total_tat = 0;
for (int i = 0 ; i < n ; i++)
{
total_wt = total_wt + wt[i];
total_tat = total_tat + tat[i];
int compl_time = tat[i] + at[i];
cout << " " << i+1 << "\t\t" << bt[i] << "\t\t" << at[i] << "\t\t" << wt[i] << "\t\t " << tat[i] << "\t\t " << compl_time << endl;
}
cout << "Average waiting time = " << (float)total_wt / (float)n;
cout << "\nAverage turn around time = " << (float)total_tat / (float)n;
}
int main()
{
int np;
cout << "Enter number of processes: ";
cin >> np;
int processes[np];
for(int &i : processes)
{
cin >> i;
}
int n = sizeof processes / sizeof processes[0];
int burst_time[np];
cout << "Enter burst time of processes: ";
for(int &i : burst_time)
{
cin >> i;
}
int arrival_time[np];
cout << "Enter arrival time of processes: ";
for(int &i : arrival_time)
{
cin >> i;
}
findavgTime(processes, n, burst_time, arrival_time);
return 0;
}