-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flights.cpp
193 lines (191 loc) · 3.93 KB
/
Flights.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "Flights.h"
#include <fstream>
Flights::Flights()
{
}
Flights::~Flights()
{
}
void Flights::addFlight(string plane, string pilot, string copilot, string crew1, string crew2, string crew3, int p)
{
cin.ignore();
string key;
string planeID = plane;
string pilotID = pilot;
string copilotID = copilot;
string c1 = crew1;
string c2 = crew2;
string c3 = crew3;
string SD;
string ED;
int ST;
int ET;
string SC;
string EC;
int pass;
int seats = p;
string stat;
cout << "Enter the ID for the flight: ";
getline(cin, key);
cout << "Enter the starting date(mm/dd/yy): ";
getline(cin, SD);
cout << "Enter the ending date(mm/dd/yy): ";
getline(cin, ED);
cout << "Enter the starting time in GMT: ";
cin >> ST;
cout << "Enter the ending time in GMT: ";
cin >> ET;
cout << "Enter the starting airport code: ";
getline(cin, SC);
cout << "Enter the ending airport code: ";
getline(cin, EC);
cout << "Enter the number of passengers: ";
cin >> pass;
while (pass > seats)
{
cout << "Plane does not have the capacity for that many passengers...\n"
<< "Enter the number of passengers: ";
cin >> pass;
}
cin.ignore();
cout << "Enter the current status of flight: ";
getline(cin, stat);
Flight tmp(planeID, pilotID, copilotID, c1, c2, c3, SD, ED, ST, ET, SC, EC, pass, stat);
Flight_List[key] = tmp;
}
void Flights::deleteFlight(string key)
{
if (key != "ERROR")
{
map <string, Flight>::iterator it;
it = Flight_List.find(key);
Flight_List.erase(it);
cout << "Flight# \"" << key << "\" has been deleted...\n";
}
else
{
cout << key << " FLIGHT NOT FOUND..." << endl;
}
}
void Flights::editFlight(string key)
{
printFlight(key);
cout << "Re-enter the following information including any changes: \n";
deleteFlight(key);
}
string Flights::findFlight()
{
string id;
string key;
cout << "Enter flight ID: ";
cin.ignore();
getline(cin, id);
map <string, Flight>::iterator it = Flight_List.find(id);
if (it != Flight_List.end())
{
key = it->first;
return key;
}
else
{
return("ERROR");
}
}
void Flights::printFlight(string key)
{
if (key != "ERROR")
{
Flight_List[key].Print();
cout << "Press enter to continue...\n";
cin.ignore();
}
else
{
cout << key << " CREW MEMBER NOT FOUND..." << endl;
}
}
void Flights::printFlights()
{
string i;
for (map <string, Flight>::iterator it = Flight_List.begin(); it != Flight_List.end(); it++)
{
cout << "ID: " << it->first << endl;
it->second.Print();
cout << endl;
}
cout << "Press enter to continue...\n";
getline(cin, i);
cin.ignore();
}
void Flights::load()
{
string key;
string planeID;
string pilotID;
string copilotID;
string cw1;
string cw2;
string cw3;
string sd;
string ed;
int st;
int et;
string sc;
string ec;
int Pass;
string status;
map <string, Flight>::iterator it;
ifstream myFile;
myFile.open("Flights.txt");
if (myFile.is_open())
{
while (!myFile.eof())
{
myFile >> key
>> planeID
>> pilotID
>> copilotID
>> cw1
>> cw2
>> cw3
>> sd
>> ed
>> st
>> et
>> sc
>> ec
>> Pass
>> status;
Flight tmp(planeID, pilotID, copilotID, cw1, cw2, cw3, sd, ed, st, et, sc, ec, Pass, status);
Flight_List[key] = tmp;
}
}
else
{
cout << "Flight List was not found..." << endl;
}
}
void Flights::store()
{
map <string, Flight>::iterator it;
ofstream myFile;
myFile.open("Flights.txt");
for (it = Flight_List.begin(); it != Flight_List.end(); it++)
{
myFile << it->first << endl
<< it->second.getPlaneID() << endl
<< it->second.getPilotID() << endl
<< it->second.getCoPilotID() << endl
<< it->second.getCrew1() << endl
<< it->second.getCrew2() << endl
<< it->second.getCrew3() << endl
<< it->second.getSdate() << endl
<< it->second.getEdate() << endl
<< it->second.getStime() << endl
<< it->second.getEtime() << endl
<< it->second.getScode() << endl
<< it->second.getEcode() << endl
<< it->second.getPass() << endl
<< it->second.getStatus() << endl;
}
}