-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
125 lines (110 loc) · 3.71 KB
/
Test.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
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include"Exceptions.h"
#include"OutputNetwork.h"
#include"PublicTransportNetwork.h"
#include<iostream>
using namespace std;
int main() {
//_crtBreakAlloc = 398;
int i = 1;
try {
string path;
cout << "Please input path to the file with information about stations" << endl;
getline(cin, path);
PublicTransportNetwork::getNetwork().readStations(path);
cout << "Stations are successfully created" << endl;
cout << "Please input path to the file with information about lines" << endl;
getline(cin, path);
PublicTransportNetwork::getNetwork().readLines(path);
cout << "Lines are successfully created" << endl;
}
catch (FileError& e) {
cout << "INPUT ERROR: " << e.what() << endl;
i = 0;
}
catch (ReadingError& e) {
cout << "INPUT ERROR: " << e.what() << endl;
i = 0;
}
catch (SearchError& e) {
cout << "INPUT ERROR: " << e.what() << endl;
i = 0;
}
while(i!=0){
cout << "Choose action:" << endl;
cout << "0.End program" << endl;
cout << "1.Output" << endl;
cout << "2.Finding path" << endl;
cin >> i;
switch (i) {
int j;
case 1: {
cout << "Choose output:" << endl;
cout << "0.End program" << endl;
cout << "1.Output stations" << endl;
cout << "2.Output lines" << endl;
cout << "3.Output lines statistic" << endl;
try {
cin >> j;
switch (j) {
case 0: i = 0;
break;
case 1: PublicTransportNetwork::getNetwork().setStationsOutputStrategy(new BasicStationsOutput());
PublicTransportNetwork::getNetwork().outputStations();
break;
case 2:PublicTransportNetwork::getNetwork().setLinesOutputStrategy(new BasicLinesOutput());
PublicTransportNetwork::getNetwork().outputLines();
break;
case 3:PublicTransportNetwork::getNetwork().setStatisticsOutputStrategy(new BasicStatisticsOutput());
PublicTransportNetwork::getNetwork().outputStatistics();
break;
default:cout << "Option " << j << " does not exists";
}
}
catch (FileError& e) {
cout << "OUTPUT ERROR: " << e.what() <<" Try again!"<<endl;
}
catch (SearchError& e) {
cout << "OUTPUT ERROR: " << e.what() << " Try again!" << endl;
}
}break;
case 2: {
int first, last;
cout << "Please enter first station code and last station code:" << endl;
cin >> first;
cin >> last;
cout << "Choose path:" << endl;
cout << "0.End program" << endl;
cout << "1.Any path" << endl;
cout << "2.Path with minimum stations" << endl;
cout << "3.Path with minimum lines" << endl;
cin >> j;
try {
switch (j) {
case 0:i = 0;
case 1:case 2:PublicTransportNetwork::getNetwork().setFindingPathsStrategy(new minimumStationsPath());
PublicTransportNetwork::getNetwork().findPath(first, last);
break;
case 3:PublicTransportNetwork::getNetwork().setFindingPathsStrategy(new MinimumLinesPath());
PublicTransportNetwork::getNetwork().findPath(first, last);
break;
}
}
catch (SearchError& e) {
cout << "SEARCH ERROR: " << e.what() << endl;
}
catch (FileError& e) {
cout << "SEARCH ERROR: " << e.what() << endl;
}
}
break;
default:
cout << "Option " << i << "does not exists" << endl;
}
}
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
return 0;
}