-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCFS.cpp
83 lines (61 loc) · 1.71 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Hannah Capone
// First Come First Served
#include <iostream>
#include <queue> // for use of queue as data structure
#include <utility> // for use of pair
#include <signal.h>
#include <unistd.h>
#include <math.h>
using namespace std;
int main()
{
queue<pair<string, int> > processes;
int waitingTimes = 0;
int turnaroundTimes = 0;
int count = 0;
string name;
int time;
int totalruntime = 0;
// Read the list until end of transmission
while (cin >> name >> time)
{
pair<string,int> pair;
pair.first = name;
pair.second = time;
processes.push(pair);
count++;
}
cout << endl;
queue<double> forThroughput;
double i = 0.0;
// FCFS Simulation
while (!processes.empty())
{
i++;
pair<string, int> temp;
temp = processes.front();
processes.pop();
sleep(temp.second);
cout << temp.first << " Finished" << endl;
waitingTimes += totalruntime;
totalruntime += temp.second;
turnaroundTimes += totalruntime;
forThroughput.push(i/totalruntime);
//cout << "### Adding to queue: " << i << "/" << totalruntime << endl;
cout << "Total Time running: " << totalruntime << endl;
}
cout << "no processes left" << endl;
cout << endl;
cout << "Average Waiting time: " << waitingTimes/count << endl;
cout << "Average Turnaround time: " << turnaroundTimes/count << endl;
// Average Throughput
double avThrough = 0.0;
while(!forThroughput.empty())
{
avThrough = avThrough + forThroughput.front();
forThroughput.pop();
}
avThrough = avThrough/count;
cout.precision(3);
cout << "Average Throughput: " << avThrough<< endl;
}