This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
85 lines (67 loc) · 2.39 KB
/
main.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
84
85
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include "Airport.h"
#include "models/Passenger.h"
#include "models/Feature.h"
typedef std::pair<Airport, std::vector<Passenger>> ParsedInput;
ParsedInput parseInput(const std::string& filename) {
std::ifstream infile(filename);
// Read the first line for airport parameters
unsigned long numPassenger, numLuggage, numSecurity;
std::string line;
getline(infile, line);
std::istringstream lss(line);
lss >> numPassenger >> numLuggage >> numSecurity;
Airport airport(numSecurity, numLuggage);
// remaining lines are passenger details
PassengerList passengers;
while (std::getline(infile, line) && numPassenger--) {
unsigned long tEntry, tFlight, waitLuggage, waitSecurity;
bool isVip, hasLuggage;
char vip, luggage;
std::istringstream ss(line);
ss >> tEntry >> tFlight >> waitLuggage >> waitSecurity >> vip >> luggage;
isVip = vip == 'V';
hasLuggage = luggage == 'L';
passengers.push_back(Passenger(
tEntry,
tFlight,
waitLuggage,
waitSecurity,
isVip,
hasLuggage
));
}
return {airport, passengers};
}
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cout << "Syntax: ./project2 <input_file> <output_file> [verbose]" << std::endl;
std::cout << "(add any character to the end to output results to the console)" << std::endl;
return 1;
}
bool verbose = argc > 3;
Feature testCases[] = {
FIRST_COME_FIRST_SERVE,
FIRST_FLY_FIRST_SERVE,
VIP_SKIP_SECURITY,
FIRST_FLY_FIRST_SERVE | VIP_SKIP_SECURITY,
ONLINE_TICKETING,
FIRST_FLY_FIRST_SERVE | ONLINE_TICKETING,
ONLINE_TICKETING | VIP_SKIP_SECURITY,
FIRST_FLY_FIRST_SERVE | VIP_SKIP_SECURITY | ONLINE_TICKETING
};
ParsedInput input = parseInput(argv[1]);
Airport airport = input.first;
PassengerList passengers = input.second;
std::ofstream outfile(argv[2], std::ios::app);
for (const auto& caseFeatures : testCases) {
airport.setFeatures(caseFeatures);
Report report = airport.run(passengers);
outfile << report << std::endl;
if (verbose) std::cout << report << std::endl;
}
return 0;
}