-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp~
179 lines (154 loc) · 4.52 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
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
#include <fstream>
#include <iostream>
#include <iomanip>
#include "graph.h"
#include <string>
#define MAX_SIZE 100
using namespace std;
int main()
{
GRAPH* g = NULL;
ifstream file;
int stationNumber, departStation, arriveStation, departTime, arriveTime, travelTime;
string stationName[MAX_SIZE];
file.open("stations.dat");
int stations = 0;
while(file >> stationNumber){
file >> stationName[stationNumber];
stations++;
}
file.close();
file.open("trains.dat");
while(file >> departStation){
file >> departStation;
file >> departStation;
file >> departStation;
}
file.close();
file.open("trains.dat");
if (!file.is_open())
{
cout << "Error: Failed to open input file\n";
return 0;
}
file >> stations;
g = new GRAPH(stations);
while (file >> departStation)
{
file >> arriveStation;
file >> departTime;
file >> arriveTime;
int min1 = (arriveTime / 100) * 60 + (arriveTime % 100);
int min2 = (departTime / 100) * 60 + (departTime % 100);
travelTime = (min1 - min2);
g->setEdge(departStation, arriveStation, travelTime, stationName, departTime, arriveTime);
}
file.close();
bool done = false;
bool found = false;
int userNum, numberCin, departCin, arriveCin, user;
string stationCin;
cout<<"\n\n=========================================================\n";
cout<<"(kur) TIS' THE TRAIN TRACKING exTRAVAGANCE\n";
cout<<"=========================================================\n\n";
while(!done){
//ask user
cout<<"Choose an option below: (enter the corresponding number)\n";
cout<<"(1) - print a complete train itinerary\n";
cout<<"(2) - print a specific train's itinerary\n";
cout<<"(3) - look up a station by number\n";
cout<<"(4) - look up a station by name\n";
cout<<"(5) - check if a(n) (in)direct route exists\n";
cout<<"(6) - shortest path to/from source/destination\n";
cout<<"(7) - exit\n";
//user response
cin >> userNum;
cout<<endl;
switch (userNum)
{
case 1:
g->printGraph();
break;
case 2:
cout<<"Which train's itinerary are you printing?\n";
cin>>numberCin;
cout << endl << endl;
g->printGraphParameter(numberCin);
break;
case 3:
cout << "Enter Station ID\n";
cin >> numberCin;
cout << endl << "Station ID " << numberCin << " : " << stationName[numberCin] << endl << endl;
break;
case 4:
cout << "Enter Station Name\n";
cin >> stationCin;
for(int i = 0; i <= stations; i++){
if(stationCin.compare(stationName[i]) == 0){
cout<<endl<<"Train ID " << i << " : " << stationName[i] << endl << endl;
found = true;
}
}
if(found == false){
cout<<"Error: The station name you entered was not found.\n\n";
}
break;
case 5:
cout<<"Departure station number: ";
cin>>departCin;
cout<<"Arrival station number: ";
cin>>arriveCin;
cout<<"\nA ";
if(g->isAdjacent(departCin,arriveCin)){
cout<<"direct";
}
else{
cout<<"non direct";
}
cout<< " route from "<<departCin<<" to "<<arriveCin;
if(g->isReachable(departCin, arriveCin)){
cout<<" does";
}
else{
cout<<" does not";
}
cout<<" exist."<< endl << endl;
break;
case 6:
cout<<"Departure station number: ";
cin>>departCin;
cout<<"Arrival station number: ";
cin>>arriveCin;
if(g->isReachable(departCin, arriveCin)){
cout<<endl<<"Depart from "<<stationName[departCin]<<" to "<<stationName[arriveCin]<<" in ";
g->dijkstra(departCin,arriveCin);
if(g->isAdjacent(departCin, arriveCin)){
cout<<" not including layovers.\n\n";
}
else{
cout<<" including layovers.\n\n";
}
g->printGraphParameter(departCin);
g->printGraphParameter(arriveCin);
}
else{
cout << "No route exists.\n\n";
}
break;
case 7:
cout<<" ''~`` \n";
cout<<" ( o o ) \n";
cout<<"+------------------.oooO--(_)--Oooo.------------------+\n";
cout<<"| Goodbye |\n";
cout<<"| .oooO |\n";
cout<<"| ( ) Oooo. |\n";
cout<<"+---------------------) (----( )--------------------+\n";
cout<<" (_) ) / \n";
cout<<" (_/ \n";
done = true;
break;
default:
cout << "Error: Not a correct option. (numbers 1-7 are allowed)\n";
}
}
}