-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
230 lines (220 loc) · 8.43 KB
/
main.cpp
File metadata and controls
230 lines (220 loc) · 8.43 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "AdjacencyListGraph.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
AdjacencyListGraph myGraph;
string inputFile;
cout << "Input the airport input file name: " << endl;
cin >> inputFile;
ifstream myFile;
myFile.open(inputFile);
string curLine;
while (std::getline(myFile,curLine))
{
string name;
string code;
for (int i = 0; i < curLine.size(); i++)
{
if (curLine[i] == ' ')
{
code = curLine.substr(0, i);//gives us a substring consisting of just the key
name = curLine.substr(i + 1, curLine.size()); // assumes the rest of the string is just the name
break;
}
}
myGraph.insertVertex(name, code);
}
myFile.close();
cout << "Input the flights input file name: " << endl;
cin>>inputFile;
myFile.open(inputFile);
string flightNumber;
string Destination;
string Source;
float cost;
while (myFile >> Source>>Destination>>cost >> flightNumber)
{
myGraph.addEdge(cost, flightNumber, Source, Destination);
}
string input1;
cout << "Choose from the following options: " << endl;
cout << "1. Display airport information" << endl;
cout << "2. Find a cheapest flight from one airport to another airport" << endl;
cout << "3. Find a cheapest roundtrip from one airport to another airport" << endl;
cout << "4. Add a flight from one airport to another airport"<<endl;
cout << "5. Delete a flight from one airport to another airport" << endl;
cout << "6. Find a flight with fewest stops from one airport to another airport"<<endl;
cout << "7. Find all flights from one airport to another airport" << endl;
cout << "8. Find an order to visit all airports starting from an airport" << endl;
cout << "9. Delete an existing airport"<<endl;
cout << "Q.Exit" << endl;
//C:\Users\keane\Downloads\P4Airports.txt
//C:\Users\keane\Downloads\P4Flights.txt
//C:\Users\keane\Downloads\P4FlightsRev1.txt
while (cin >> input1)
{
int input;
if (input1 == "Q")
{
input = -1;
}
else
{
input = std::stoi(input1);
}
switch (input) {
case 1: {
cout << "Enter the source airport code (enter 0 to display all airports): " << endl;
string soruce;
cin >> soruce;
if (soruce == "0")
{
myGraph.displayNodes();
break;
}
myGraph.displayNode(soruce);
break;
}
case 2: {
cout << "Enter the source airport code: " << endl;
string soruce;
cin >> soruce;
cout << "Enter the destination airport code: " << endl;
string dsetination;
cin >> dsetination;
myGraph.printDijkstra(soruce, dsetination);
break;
}
case 3: {
cout << "Enter the source airport code: " << endl;
string soruce;
cin >> soruce;
cout << "Enter the destination airport code: " << endl;
string dsetination;
cin >> dsetination;
myGraph.printDijkstraRoundTrip(soruce, dsetination);
break;
}
case 4: {
cout << "Enter the code of the source city: " << endl;
string soruce;
cin >> soruce;
cout << "Enter the code of the destination city: " << endl;
string dsetination;
cin >> dsetination;
cout << "Enter the flight number: " << endl;
string fNumber;
cin >> fNumber;
cout << "Finally, enter the cost: " << endl;
float cosut;
cin >> cosut;
myGraph.addEdge(cosut, fNumber, soruce, dsetination);
cout << "Added successfully" << endl;
break;
}
case 5: {
cout << "Enter the flight code (Enter 1) or enter the source and destination node codes (Enter 2)? " << endl;
int inpuit;
cin >> inpuit;
switch (inpuit) {
case 1:
{
cout << "Enter flight code: " << endl;
string tbdeleted;
cin >> tbdeleted;
myGraph.deleteEdge(tbdeleted);
//cout << "Deleted successfully" << endl;
break;
}
case 2:
{
cout << "Enter source airport code: " << endl;
string soruce;
cin >> soruce;
cout << "Enter the destination airport code: " << endl;
string dsetination;
cin >> dsetination;
myGraph.deleteEdge(soruce, dsetination);
cout << "Deleted successfully" << endl;
break;
}
default:
cout << "Deletion cancelled" << endl;
break;
}
break;
}
case 6: {
cout << "Enter the source airport code: " << endl;
string soruce;
cin >> soruce;
cout << "Enter the destination airport code: " << endl;
string dsetination;
cin >> dsetination;
myGraph.printDijkstraNode(soruce, dsetination);
break;
}
case 7:
{
cout << "Enter the source airport code: " << endl;
string soruce;
cin >> soruce;
cout << "Enter the destination airport code: " << endl;
string dsetination;
cin >> dsetination;
myGraph.AllPathsDisplay(soruce, dsetination);
break;
}
case 8: {
cout << "Enter the starting airport: " << endl;
string startPort;
cin>>startPort;
myGraph.TraverseAllDisplay(startPort);
break;
}
case 9: {
cout << "Enter the code of the airport to be deleted: " << endl;
string tbdeleted;
cin >> tbdeleted;
myGraph.deleteNode(tbdeleted);
break;
}
case 0: {
myGraph.displayAll();
break;
}
case -1:
{
cout << "Enter the name of the output file for the updated flights: " << endl;
string p = "C:\\Users\\keane\\Downloads\\P4FlightsRev1.txt";//doing it manually because for some reason i cannot get this to work/
myGraph.displayEdges(p);
cin >> p;
myGraph.displayEdges(p);
cout << "Confirm exit? (Q) " << endl;
string qw;
cin >> qw;
if (qw == "Q")
{
exit(0);
}
break;
}
default:
break;
}
cout << "Choose from the following options: " << endl;
cout << "1. Display airport information" << endl;
cout << "2. Find a cheapest flight from one airport to another airport" << endl;
cout << "3. Find a cheapest roundtrip from one airport to another airport" << endl;
cout << "4. Add a flight from one airport to another airport" << endl;
cout << "5. Delete a flight from one airport to another airport" << endl;
cout << "6. Find a flight with fewest stops from one airport to another airport" << endl;
cout << "7. Find all flights from one airport to another airport" << endl;
cout << "8. Find an order to visit all airports starting from an airport" << endl;
cout << "9. Delete an existing airport" << endl;
cout << "Q.Exit" << endl;
}
}