-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
319 lines (283 loc) · 10.1 KB
/
main.cpp
File metadata and controls
319 lines (283 loc) · 10.1 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include "ordered.h"
#include "u_map.h"
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
bool menu = true;
int userMap;
int userOption;
clock_t startOrdBuild, endOrdBuild, startUnBuild, endUnBuild;
cout << "Building data structures..." << endl;
startOrdBuild = clock();
weatherMap ordered;
endOrdBuild = clock();
startUnBuild = clock();
u_map unordered;
endUnBuild = clock();
cout << "Time to build Unordered Map: "
<< (endUnBuild - startUnBuild) / (float)CLOCKS_PER_SEC
<< " seconds" << endl;
cout << "Time of to build Ordered Map: "
<< (endOrdBuild - startOrdBuild) / (float)CLOCKS_PER_SEC
<< " seconds" << endl << endl;
while (menu)
{
cout << "Welcome to Weather Sort!" << endl;
cout << "------------------------" << endl;
cout << "Menu:" << endl;
cout << "1). Search by average temperature" << endl;
cout << "2). Search by minimum temperature" << endl;
cout << "3). Search by maximum temperature" << endl;
cout << "4). Search by wind speed" << endl;
cout << "5). Search by precipitation" << endl;
cout << "6). Exit" << endl;
cout << "Enter option: ";
cin >> userOption;
cout << endl;
clock_t startOrdered, endOrdered, startUnordered, endUnordered;
switch (userOption)
{
case 1:
{
double min;
double max;
cout << "What is the minimum temperature you desire?" << endl;
cin >> min;
cout << "What is the maximum temperature you desire?" << endl;
cin >> max;
startUnordered = clock();
vector<pair<int, string>> resultsUnordered = unordered.avgTemp(min, max);
endUnordered = clock();
cout << "Your optimal location(s) are: " << endl;
if (resultsUnordered.size() != 0)
{
cout << resultsUnordered[0].second;
}
for (int i = 1; i < resultsUnordered.size(); i++)
{
if (resultsUnordered[i].first == resultsUnordered[0].first)
{
cout << " | " << resultsUnordered[i].second;
}
else
{
break;
}
}
cout << endl;
// ordered
startOrdered = clock();
vector<pair<int, string>> resultsOrdered = ordered.avgTemp(min, max);
endOrdered = clock();
cout << endl << "Time of Unordered Map: "
<< (endUnordered - startUnordered) / (float)CLOCKS_PER_SEC
<< " seconds" << endl;
cout << "Time of Ordered Map: "
<< (endOrdered - startOrdered) / (float)CLOCKS_PER_SEC << " seconds"
<< endl;
menu = false;
break;
}
case 2:
{
double minTemperature;
cout << "What is the minumum temperature you desire?" << endl;
cin >> minTemperature;
startUnordered = clock();
vector<pair<int, string>> resultsUnordered = unordered.minTemp(minTemperature);
endUnordered = clock();
cout << "Your optimal location(s) are: " << endl;
// this should print out first element of vector and those with the same
// freq. as it
if (resultsUnordered.size() != 0)
{
cout << resultsUnordered[0].second;
}
for (int i = 1; i < resultsUnordered.size(); i++)
{
if (resultsUnordered[i].first == resultsUnordered[0].first)
{
cout << " | " << resultsUnordered[i].second;
}
else
{
break;
}
}
cout << endl;
// ordered
startOrdered = clock();
vector<pair<int, string>> resultsOrdered = ordered.minTemp(minTemperature);
endOrdered = clock();
cout << "Time of Unordered Map: "
<< (endUnordered - startUnordered) / (float)CLOCKS_PER_SEC
<< " seconds" << endl;
cout << "Time of Ordered Map: "
<< (endOrdered - startOrdered) / (float)CLOCKS_PER_SEC << " seconds"
<< endl;
menu = false;
break;
}
case 3:
{
double maxTemperature;
cout << "What is the maximum temperature you desire?" << endl;
cin >> maxTemperature;
// unordered
startUnordered = clock();
vector<pair<int, string>> resultsUnordered = unordered.maxTemp(maxTemperature);
endUnordered = clock();
cout << "Your optimal location(s) are: " << endl;
if (resultsUnordered.size() != 0)
{
cout << resultsUnordered[0].second;
}
for (int i = 1; i < resultsUnordered.size(); i++)
{
if (resultsUnordered[i].first == resultsUnordered[0].first)
{
cout << " | " << resultsUnordered[i].second;
}
else
{
break;
}
}
cout << endl;
// ordered
startOrdered = clock();
vector<pair<int, string>> resultsOrdered = ordered.maxTemp(maxTemperature);
endOrdered = clock();
cout << "Time of Unordered Map: "
<< (endUnordered - startUnordered) / (float)CLOCKS_PER_SEC
<< " seconds" << endl;
cout << "Time of Ordered Map: "
<< (endOrdered - startOrdered) / (float)CLOCKS_PER_SEC << " seconds"
<< endl;
menu = false;
break;
}
case 4:
{
double minwindSpeed, maxWindSpeed;
cout << "What is minimum wind speed you desire?" << endl;
cin >> minwindSpeed;
cout << "What is the maximum wind speed you desire?" << endl;
cin >> maxWindSpeed;
// unordered
startUnordered = clock();
vector<pair<int, string>> resultsUnordered = unordered.windSpd(minwindSpeed, maxWindSpeed);
endUnordered = clock();
cout << "Your optimal location(s) are: " << endl;
if (resultsUnordered.size() != 0)
{
cout << resultsUnordered[0].second;
}
for (int i = 1; i < resultsUnordered.size(); i++)
{
if (resultsUnordered[i].first == resultsUnordered[0].first)
{
cout << " | " << resultsUnordered[i].second;
}
else
{
break;
}
}
cout << endl;
// ordered
startOrdered = clock();
vector<pair<int, string>> resultsOrdered = ordered.windSpeed(minwindSpeed, maxWindSpeed);
endOrdered = clock();
cout << "Time of Unordered Map: "
<< (endUnordered - startUnordered) / (float)CLOCKS_PER_SEC
<< " seconds" << endl;
cout << "Time of Ordered Map: "
<< (endOrdered - startOrdered) / (float)CLOCKS_PER_SEC << " seconds"
<< endl;
menu = false;
break;
}
case 5:
{
double minPrecipitation, maxPrecipitation;
cout << "What is the minimum precipitation you desire?" << endl;
cin >> minPrecipitation;
cout << "What is the maximum precipitation you desire?" << endl;
cin >> maxPrecipitation;
// unordered
startUnordered = clock();
vector<pair<int, string>> results = unordered.precip(minPrecipitation, maxPrecipitation);
endUnordered = clock();
cout << "Your optimal location(s) are: " << endl;
if (results.size() != 0)
{
cout << results[0].second;
}
for (int i = 1; i < results.size(); i++)
{
if (results[i].first == results[0].first)
{
cout << " | " << results[i].second;
}
else
{
break;
}
}
cout << endl;
// ordered
startOrdered = clock();
vector<pair<int, string>> resultsOrdered = ordered.precipitation(minPrecipitation, maxPrecipitation);
endOrdered = clock();
cout << "Time of Unordered Map: "
<< (endUnordered - startUnordered) / (float)CLOCKS_PER_SEC
<< " seconds" << endl;
cout << "Time of Ordered Map: "
<< (endOrdered - startOrdered) / (float)CLOCKS_PER_SEC << " seconds"
<< endl;
menu = false;
break;
}
case 6:
cout << "Thank you for using Weather Sort!" << endl;
menu = false;
break;
default:
cout << "Invalid menu option. Please try again" << endl;
break;
}
while (!menu)
{
if (userOption == 6)
{
break;
}
int userInput;
cout << endl << "Would you like to select a menu option again?" << endl;
cout << "1). Yes" << endl;
cout << "2). No" << endl;
cout << "Enter option: ";
cin >> userInput;
cout << endl;
if (userInput == 1)
{
menu = true;
}
else if (userInput == 2)
{
cout << "Thank you for using Weather Sort!" << endl;
break;
}
else
{
cout << "Invalid input. Please enter valid input" << endl;
break;
}
}
}
return 0;
}