-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
2213 lines (1726 loc) · 100 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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! \file */
/**
* @brief Ficheiro onde estão implementados os diferentes menus com as funcionalidades pedidas no enunciado do projeto
*/
#include <bits/stdc++.h>
#include "../headers/Ler.h"
using namespace std;
Ler lfile;
Graph g;
void clearScreen();
void wait();
// Checks
bool checkInteiro(const string& s);
bool checkAeroporto(const string& s);
bool checkCidade(const string& s);
bool checkPais(const string& s);
bool checkCoordenadas(double lat, double lon);
bool checkRaio(const string& s);
bool checkDouble(const string& s);
vector<int> checkPaisCidade(const string& cidade);
// Other Menu Functions
void menu_me_aerop_dest(const string& aerop);
vector<int> aeroportos_pais(const string& pais);
string aeroporto_mais_proximo(double lat, double lon);
vector<int> aeroportos_num_raio_x(double lat, double lon, double raio);
// Prints de Menu Informacao
void print_info_aeroporto(int id, const Aeroporto& aeroporto, string aerop);
void print_info_cidade(const string& cidade);
void print_info_aeroporto_cidade(const string& cidade);
void print_info_aeroporto_cidade_pais(const string& cidade, const string& pais);
void print_info_pais(const string& pais);
void print_info_aeroporto_pais(const string& pais, vector<int> aeroportos);
void print_info_aeroporto_num_raio_x(double latitude, double longitude, double raio);
void print_voos(int origem, int destino);
int main(){
system("Color 09");
lfile.ler_aeroportos();
g = Graph((int) lfile.getAeroportos().size());
lfile.ler_companhias();
lfile.ler_voos(g);
int diametro = g.diametro();
// vector<int> aeroportos com maximo de voos
vector<pair<int,int>> aeroportos_max_voos; //partida e chegada
for(int x = 1; x <= g.n; x++) {
g.bfs(x);
for (int i = 1; i <= g.n; i++) {
if (g.nodes[i].distance == diametro) {
pair<int,int> aeroporto = make_pair(x,i);
aeroportos_max_voos.push_back(aeroporto);
}
}
}
int choice;
string op_menu;
string aerop, cidade, pais;
// Variaveis para o menu 1 - 1
Aeroporto aeroporto;
int id;
// Variaveis para o menu 1 - 4
double lat, lon;
double raio;
string raio_s;
string batata;
vector<int> pais_cidade;
vector<int> aeroportos_pais_v;
vector<int> aeroportos_raio;
vector<pair<int,string>> aeroportos_companhias;
vector<pair<string, int>> voos_por_aeroporto_v;
unordered_set<int> companhias_pais;
vector<string> aero_codigo_temp;
int contador_companhias_pais;
int cont_partida_voos;
int cont_chegada_voos;
int cont_voos_partida_temp, cont_voos_chegada_temp;
unordered_map<string, int> paises_num_aeroporto;
string pais_est_temp;
int destinos_est_temp = 0;
int paises_tmp_total = 0;
int companhias_est_temp = 0;
int rnd;
string n_voos;
vector<int> voos_n_dist;
set<int> ap;
int index = 1;
stack<int> node_stack;
list<list<int>> sccs;
int scc = 0;
int min = INT_MAX;
int max = 0;
do {
/**
* Menu Principal
*/
clearScreen();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||------------------------ MENU -------------------------||" << endl;
cout << "|| Escolha uma opcao: ||" << endl;
cout << "||_______________________________________________________||" << endl;
cout << "|| ||" << endl;
cout << "|| 1 - Informacoes ||" << endl;
cout << "|| 2 - Pesquisa ||" << endl;
cout << "|| 3 - Estatisticas ||" << endl;
cout << "|| ||" << endl;
cout << "|| 0 - Sair ||" << endl;
cout << "|| ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << endl;
/** Leitura do input do utilizador **/
cin >> op_menu;
while(!checkInteiro(op_menu) || stoi(op_menu) < 0 || stoi(op_menu) > 3){
cout << endl;
cout << "Opcao invalida! Tente novamente: ";
cin >> op_menu;
cout << endl;
}
choice = stoi(op_menu);
cout << endl;
/** Estrutura utillizada para realizar as varias funçoes disponibilizadas no menu. */
switch (choice) {
case 0:
choice = 0;
/** Opção para sair do programa. */
break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 1:
int ch1;
choice = 1;
/** Opção para aceder ao menu de informação. */
do{
/**
* Menu Informacao
*/
clearScreen();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||------------------------ INFO -------------------------||" << endl;
cout << "|| Escolha uma opcao: ||" << endl;
cout << "||_______________________________________________________||" << endl;
cout << "|| ||" << endl;
cout << "|| 1 - De um Aeroporto ||" << endl;
cout << "|| 2 - De uma Cidade ||" << endl;
cout << "|| 3 - De um Pais ||" << endl;
cout << "|| 4 - De um raio de X Km de uma coordenada ||" << endl;
cout << "|| ||" << endl;
cout << "|| 0 - Sair ||" << endl;
cout << "|| ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << endl;
/** Leitura do input do utilizador **/
cin >> op_menu;
/** Verifica se o input é um inteiro e se está dentro do intervalo de opções disponiveis. */
while(!checkInteiro(op_menu) || stoi(op_menu) < 0 || stoi(op_menu) > 4){
cout << endl;
cout << "Opcao invalida! Tente novamente: ";
cin >> op_menu;
cout << endl;
}
ch1 = stoi(op_menu);
switch (ch1) {
case 0:
ch1 = 0;
/** Opção para sair do menu de informação. */
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 1:
/** Opção para aceder ao menu de informação de um aeroporto. */
cout << "Aeroporto: ";
cin >> aerop;
/** Leitura do input do utilizador */
/** Verifica se o aeroporto existe. */
while(!checkAeroporto(aerop)){
clearScreen();
cout << endl;
cout << "Aeroporto invalido! Tente novamente: ";
cin >> aerop;
cout << endl;
}
transform(aerop.begin(), aerop.end(), aerop.begin(), ::toupper);
id = lfile.getAeroportosCodigos()[aerop];
aeroporto = lfile.getAeroportos().at(id);
/** Imprime as informações do aeroporto. */
print_info_aeroporto(id, aeroporto, aerop);
ch1 = 1;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 2:
cout << "Cidade: ";
getline(cin >> ws, cidade);
/** Leitura do input do utilizador */
/** Verifica se a cidade existe. */
while(!checkCidade(cidade)){
clearScreen();
cout << endl;
cout << "Cidade invalida! Tente novamente: ";
getline(cin >> ws, cidade);
cout << endl;
}
transform(cidade.begin(), cidade.end(), cidade.begin(), ::toupper);
/** Imprime as informações da cidade. */
print_info_cidade(cidade);
ch1 = 2;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 3:
cout << "Pais: ";
getline(cin >> ws, pais);
/** Leitura do input do utilizador */
/** Verifica se o pais existe. */
while(!checkPais(pais)){
clearScreen();
cout << endl;
cout << "Pais invalido! Tente novamente: ";
getline(cin >> ws, pais);
cout << endl;
}
transform(pais.begin(), pais.end(), pais.begin(), ::toupper);
/** Imprime as informações do pais. */
print_info_pais(pais);
ch1 = 3;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 4:
cout << "Coordenadas: " << endl;
cout << " - Latitude: ";
cin >> lat;
cout << endl;
cout << " - Longitude: ";
cin >> lon;
/** Leitura do input do utilizador */
/** Verifica se as coordenadas estão dentro do intervalo de valores possiveis. */
while(!checkCoordenadas(lat, lon)){
clearScreen();
cout << endl;
cout << "Coordenadas invalidas! Tente novamente: " << endl;
cout << " - Latitude: ";
cin >> lat;
cout << endl;
cout << " - Longitude: ";
cin >> lon;
}
cout << endl;
cout << " - Raio a pesquisar (Km): ";
cin >> raio;
/** Leitura do input do utilizador */
raio_s = to_string(raio);
while(!checkRaio(raio_s)){
clearScreen();
cout << endl;
cout << "Raio invalido! Tente novamente: " << endl;
cout << " - Raio a pesquisar (Km): ";
cin >> raio_s;
}
/** Verifica se o raio é válido. */
raio = stoi(raio_s);
print_info_aeroporto_num_raio_x(lat, lon, raio);
/** Imprime as informações dos aeroportos dentro do raio. */
ch1 = 4;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
default:
clearScreen();
cout << "Opcao invalida! Tente novamente." << endl;
wait();
break;
/** Opção default caso o input do utilizador não seja válido. */
}
} while (ch1 != 0);
break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 2:
/** Opção para aceder ao menu de pesquisa de rotas. */
int ch2;
choice = 2;
do{
/** Menu de pesquisa de rotas. */
clearScreen();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||---------------------- PESQUISA -----------------------||" << endl;
cout << "|| Escolha uma opcao: ||" << endl;
cout << "||_______________________________________________________||" << endl;
cout << "|| ||" << endl;
cout << "|| 1 - Rota com menos escalas ||" << endl;
cout << "|| 2 - Destinos com menos de n voos ||" << endl;
cout << "|| ||" << endl;
cout << "|| 0 - Sair ||" << endl;
cout << "|| ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << endl;
cin >> op_menu;
/** Leitura do input do utilizador */
while(!checkInteiro(op_menu) || stoi(op_menu) < 0 || stoi(op_menu) > 2){
cout << endl;
cout << "Opcao invalida! Tente novamente: ";
cin >> op_menu;
cout << endl;
}
/** Verifica se o input do utilizador é válido. */
ch2 = stoi(op_menu);
switch (ch2) {
case 0:
/** Opção para sair do menu de pesquisa de rotas. */
ch2 = 0;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 1:
/** Opção para pesquisar a rota com menos escalas. */
ch2 = 1;
int ch2_1;
do{
/** Menu de pesquisa de rotas com menos escalas. */
clearScreen();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||---------------------- PESQUISA -----------------------||" << endl;
cout << "|| Origem do Voo: (Menos Escalas) ||" << endl;
cout << "||_______________________________________________________||" << endl;
cout << "|| ||" << endl;
cout << "|| 1 - Um Aeroporto ||" << endl;
cout << "|| 2 - Uma Cidade ||" << endl;
cout << "|| 3 - Um Pais ||" << endl;
cout << "|| 4 - O Aeroporto mais proximo de umas coordenadas ||" << endl;
cout << "|| 5 - Todos os pontos num raio de X Km ||" << endl;
cout << "|| ||" << endl;
cout << "|| 0 - Sair ||" << endl;
cout << "|| ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << endl;
cin >> op_menu;
while(!checkInteiro(op_menu) || stoi(op_menu) < 0 || stoi(op_menu) > 5){
cout << endl;
cout << "Opcao invalida! Tente novamente: ";
cin >> op_menu;
cout << endl;
}
/** Verifica se o input do utilizador é válido. */
ch2_1 = stoi(op_menu);
switch (ch2_1) {
case 0:
/** Opção para sair do menu de pesquisa de rotas com menos escalas. */
ch2_1 = 0;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 1:
/** Opção para pesquisar a rota com menos escalas a partir de um aeroporto. */
cout << "Aeroporto: ";
cin >> aerop;
/** Leitura do input do utilizador */
while(!checkAeroporto(aerop)){
clearScreen();
cout << endl;
cout << "Aeroporto invalido! Tente novamente: ";
cin >> aerop;
cout << endl;
}
/** Verifica se o aeroporto é válido. */
transform(aerop.begin(), aerop.end(), aerop.begin(), ::toupper);
menu_me_aerop_dest(aerop);
ch2_1 = 1;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 2:
/** Opção para pesquisar a rota com menos escalas a partir de uma cidade. */
cout << "Cidade: ";
getline(cin >> ws, cidade);
/** Leitura do input do utilizador */
while(!checkCidade(cidade)){
clearScreen();
cout << endl;
cout << "Cidade invalida! Tente novamente: ";
getline(cin >> ws, cidade);
cout << endl;
}
/** Verifica se a cidade é válida. */
transform(cidade.begin(), cidade.end(), cidade.begin(), ::toupper);
pais_cidade = checkPaisCidade(cidade);
/** Verifica se a cidade pertence a algum país. */
if(lfile.getCidadesAeroportos().find(cidade)->second.size() == 1){
aerop = lfile.getAeroportos().find(lfile.getCidadesAeroportos().find(cidade)->second[0])->second.getCodigo();
menu_me_aerop_dest(aerop);
} /** Verifica se a cidade tem apenas um aeroporto */
else{
clearScreen();
cout << "===========================================================" << endl;
cout << " Cidade com mais de um aeroporto. Escolha um: " << endl;
for(auto i : pais_cidade){
cout << lfile.getAeroportos().find(i)->second.getCodigo() << " - " << lfile.getAeroportos().find(i)->second.getNome() << endl;
} /** Imprime todos os aeroportos da cidade */
cout << "===========================================================" << endl;
cout << endl;
cout << "Aeroporto: ";
cin >> aerop;
/** Leitura do input do utilizador */
while(!checkAeroporto(aerop)){
clearScreen();
cout << endl;
cout << "Aeroporto invalido! Tente novamente: ";
cin >> aerop;
cout << endl;
}
/** Verifica se o aeroporto é válido. */
transform(aerop.begin(), aerop.end(), aerop.begin(), ::toupper);
menu_me_aerop_dest(aerop);
}
ch2_1 = 2;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 3:
cout << "Pais: ";
getline(cin >> ws, pais);
/** Leitura do input do utilizador */
while(!checkPais(pais)){
clearScreen();
cout << endl;
cout << "Pais invalido! Tente novamente: ";
getline(cin >> ws, pais);
cout << endl;
}
/** Verifica se o país é válido. */
transform(pais.begin(), pais.end(), pais.begin(), ::toupper);
aeroportos_pais_v = aeroportos_pais(pais);
if(aeroportos_pais_v.size() == 1) {
aerop = to_string(aeroportos_pais_v[0]);
menu_me_aerop_dest(aerop);
} /** Verifica se o país tem apenas um aeroporto */
else{
clearScreen();
cout << "===========================================================" << endl;
cout << " Pais com mais de um aeroporto. Escolha um: " << endl;
for(auto i : aeroportos_pais_v){
cout << lfile.getAeroportos().find(i)->second.getCodigo() << " - " << lfile.getAeroportos().find(i)->second.getNome() << endl;
} /** Imprime todos os aeroportos do país */
cout << "===========================================================" << endl;
cout << endl;
cout << "Aeroporto: ";
cin >> aerop;
/** Leitura do input do utilizador */
while(!checkAeroporto(aerop)){
clearScreen();
cout << endl;
cout << "Aeroporto invalido! Tente novamente: ";
cin >> aerop;
cout << endl;
} /** Verifica se o aeroporto é válido. */
transform(aerop.begin(), aerop.end(), aerop.begin(), ::toupper);
menu_me_aerop_dest(aerop);
}
ch2_1 = 3;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 4:
cout << "Coordenadas: " << endl;
cout << " - Latitude: ";
cin >> lat;
cout << endl;
cout << " - Longitude: ";
cin >> lon;
/** Leitura do input do utilizador */
while(!checkCoordenadas(lat, lon)){
clearScreen();
cout << endl;
cout << "Coordenadas invalidas! Tente novamente: " << endl;
cout << " - Latitude: ";
cin >> lat;
cout << endl;
cout << " - Longitude: ";
cin >> lon;
} /** Verifica se as coordenadas são válidas. */
aerop = aeroporto_mais_proximo(lat, lon);
clearScreen();
cout << "===========================================================" << endl;
cout << " Cidade mais proxima: " << lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aerop)->second)->second.getCidade() << endl;
cout << endl;
cout << " Aeroporto mais proximo: " << endl;
cout << " [" << lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aerop)->second)->second.getCodigo()
<< "] - " << lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aerop)->second)->second.getNome() << endl;
cout << endl;
cout << " Distancia: " << distancia(lat, lon, lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aerop)->second)->second.getLatitude(),lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aerop)->second)->second.getLongitude());
cout << " km" << endl;
cout << "===========================================================" << endl;
wait();
menu_me_aerop_dest(aerop);
ch2_1 = 4;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
case 5:
cout << "Coordenadas: " << endl;
cout << " - Latitude: ";
cin >> lat;
cout << endl;
cout << " - Longitude: ";
cin >> lon;
/** Leitura do input do utilizador */
while(!checkCoordenadas(lat, lon)){
clearScreen();
cout << endl;
cout << "Coordenadas invalidas! Tente novamente: " << endl;
cout << " - Latitude: ";
cin >> lat;
cout << endl;
cout << " - Longitude: ";
cin >> lon;
} /** Verifica se as coordenadas são válidas. */
cout << endl;
cout << " - Raio a pesquisar (Km): ";
cin >> raio;
raio_s = to_string(raio);
while(!checkRaio(raio_s)){
clearScreen();
cout << endl;
cout << "Raio invalido! Tente novamente: " << endl;
cout << " - Raio a pesquisar (Km): ";
cin >> raio_s;
} /** Verifica se o raio é válido. */
raio = stoi(raio_s);
aeroportos_raio = aeroportos_num_raio_x(lat, lon, raio);
if(aeroportos_raio.empty()){
clearScreen();
cout << "===========================================================" << endl;
cout << " Nao existem aeroportos no raio indicado!" << endl;
cout << "===========================================================" << endl;
wait();
ch2_1 = 5;
break;
} /** Verifica se existem aeroportos no raio indicado. */
clearScreen();
cout << "===========================================================" << endl;
cout << " Aeroportos no raio de " << raio << " km: " << endl;
cout << endl;
for(auto i : aeroportos_raio){
cout << " [" << lfile.getAeroportos().find(i)->second.getCodigo()
<< "] - " << lfile.getAeroportos().find(i)->second.getNome() << endl;
} /** Imprime os aeroportos no raio indicado. */
cout << endl;
cout << "===========================================================" << endl;
cout << "| Escollha um aeroporto: |" << endl;
cout << "===========================================================" << endl;
cout << endl;
cout << "Aeroporto: ";
cin >> aerop;
/** Leitura do input do utilizador */
while(!checkAeroporto(aerop)){
clearScreen();
cout << endl;
cout << "Aeroporto invalido! Tente novamente: ";
cin >> aerop;
cout << endl;
} /** Verifica se o aeroporto é válido. */
transform(aerop.begin(), aerop.end(), aerop.begin(), ::toupper);
menu_me_aerop_dest(aerop);
ch2_1 = 5;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
default:
clearScreen();
cout << "Opcao invalida! Tente novamente." << endl;
wait();
break;
/** Caso o utilizador insira uma opção inválida. */
}
} while (ch2_1 != 0);
break;
case 2:
/** opção destinos com menos de n voos */
cout << "Aeroporto de partida: ";
cin >> aerop;
cout << endl;
/** Leitura do input do utilizador */
while(!checkAeroporto(aerop)){
clearScreen();
cout << endl;
cout << "Aeroporto invalido! Tente novamente: ";
cin >> aerop;
cout << endl;
}
/** Verifica se o aeroporto é válido. */
transform(aerop.begin(), aerop.end(), aerop.begin(), ::toupper);
cout << "Numero de voos: ";
cin >> n_voos;
/** Leitura do input do utilizador */
while(!checkInteiro(n_voos)){
clearScreen();
cout << endl;
cout << "Numero de voos invalido! Tente novamente: ";
cin >> n_voos;
cout << endl;
} /** Verifica se o número de voos é válido. */
g.bfs((int) lfile.getAeroportosCodigos().find(aerop)->second);
for(int i = 1; i <= g.n; i++){
if(g.nodes[i].distance <= stoi(n_voos)){
voos_n_dist.push_back(i);
}
}
clearScreen();
cout << "===========================================================" << endl;
cout << "|------------------------- INFO --------------------------|" << endl;
cout << "| Aeroporto de origem: " + aerop + " |" << endl;
cout << "|=========================================================|" << endl;
cout << " Consegue chegar a " << voos_n_dist.size() << " aeroportos em " << n_voos << " voos ou menos." << endl;
cout << endl;
cout << " Aeroportos:" << endl;
cout << endl;
for(int i : voos_n_dist){
cout << " - [" << lfile.getAeroportos().at(i).getCodigo() << "] -> " << lfile.getAeroportos().at(i).getNome() << endl;
}
cout << endl;
cout << "| |" << endl;
cout << "===========================================================" << endl;
voos_n_dist.clear();
wait();
ch1 = 5;
break;
/*---------------------------------------------------------------------------------------------------------------------------------------*/
default:
clearScreen();
cout << "Opcao invalida!" << endl;
wait();
break;
/** Caso o utilizador insira uma opção inválida. */
}
} while (ch2 != 0);
break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 3:
/** Abre o menu de estatisticas */
choice = 3;
int ch3;
do{
clearScreen();
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||-------------------- ESTATISTICAS ---------------------||" << endl;
cout << "|| Escolha uma opcao: ||" << endl;
cout << "||_______________________________________________________||" << endl;
cout << "|| ||" << endl;
cout << "|| 1 - Globais ||" << endl;
cout << "|| 2 - De um Pais ||" << endl;
cout << "|| 3 - De um Aeroporto ||" << endl;
cout << "|| 4 - Pontos de Articulacao ||" << endl;
cout << "|| 5 - Componentes Fortemente Conexos ||" << endl;
cout << "|| ||" << endl;
cout << "|| 0 - Sair ||" << endl;
cout << "|| ||" << endl;
cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << endl;
cin >> op_menu;
/** Leitura do input do utilizador */
while(!checkInteiro(op_menu) || stoi(op_menu) < 0 || stoi(op_menu) > 5){
cout << endl;
cout << "Opcao invalida! Tente novamente: ";
cin >> op_menu;
cout << endl;
} /** Verifica se a opção é válida. */
ch3= stoi(op_menu);
switch (ch3) {
case 1:
/** opção estatisticas globais */
rnd = (rand() % (10 - 3 + 1) + 3);
clearScreen();
cout << "===========================================================" << endl;
cout << "|--------------------- ESTATISTICAS ----------------------|" << endl;
cout << "| Globais |" << endl;
cout << "|=========================================================|" << endl;
cout << " " << endl;
cout << " Paises com aeroportos: " << lfile.getPaisCidades().size() << " " << endl;
cout << " Aeroportos totais: " << lfile.getAeroportos().size() << " " << endl;
cout << " Companhias: " << lfile.getCompanhias().size() << " " << endl;
cout << " Diametro da Rede: " << diametro << " " << endl;
cout << endl;
cout << " Top " << rnd <<" Aeroportos com mais companhias aereas: " << endl;
for(auto& elem : lfile.getAeroportosCompanhias()) {
aeroportos_companhias.emplace_back(elem.second.size(), elem.first);
}
sort(aeroportos_companhias.begin(), aeroportos_companhias.end(), [](const pair<int, string>& a, const pair<int, string>& b) {return a.first > b.first;});
for(int i = 0; i < rnd; i++) {
cout << " " << i+1 << " -> "
<< lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aeroportos_companhias[i].second)->second)->second.getNome() << ", "
<< lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(aeroportos_companhias[i].second)->second)->second.getPais()
<< " - " << aeroportos_companhias[i].first << endl;
}
cout << endl;
if(aeroportos_max_voos.size() > 1 ){
if(aeroportos_max_voos.size() > 5) rnd = (rand() % (5 - 2 + 1) + 2);
else (rand() % (aeroportos_max_voos.size() - 2 + 1) + 2);
cout << " As " << rnd <<" maiores viagens na rede global: " << endl;
for(int i = 0; i < rnd; i++){
cout << " " << i+1
<< " -> [" << lfile.getAeroportos().find(aeroportos_max_voos[i].first)->second.getCodigo()
<< "] -> [" << lfile.getAeroportos().find(aeroportos_max_voos[i].second)->second.getCodigo() << "]" << endl
<< " " << lfile.getAeroportos().find(aeroportos_max_voos[i].first)->second.getNome() << ", "
<< lfile.getAeroportos().find(aeroportos_max_voos[i].first)->second.getPais()
<< " - "
<< lfile.getAeroportos().find(aeroportos_max_voos[i].second)->second.getNome() << ", "
<< lfile.getAeroportos().find(aeroportos_max_voos[i].second)->second.getPais();
cout << endl;
}
}
else{
cout << " A maiore viagem na rede global: " << endl;
cout << " " << 1
<< " -> [" << lfile.getAeroportos().find(aeroportos_max_voos[0].first)->second.getCodigo()
<< "] -> [" << lfile.getAeroportos().find(aeroportos_max_voos[0].second)->second.getCodigo() << "]" << endl
<< " " << lfile.getAeroportos().find(aeroportos_max_voos[0].first)->second.getNome() << ", "
<< lfile.getAeroportos().find(aeroportos_max_voos[0].first)->second.getPais()
<< " -> "
<< lfile.getAeroportos().find(aeroportos_max_voos[0].second)->second.getNome() << ", "
<< lfile.getAeroportos().find(aeroportos_max_voos[0].second)->second.getPais();
cout << endl;
}
cout << "| |" << endl;
cout << "===========================================================" << endl;
cout << endl;
aeroportos_companhias.clear();
wait();
break;
case 2:
/** opção estatisticas por pais */
cout << "Pais: ";
getline(cin >> ws, pais);
while(!checkPais(pais)){
clearScreen();
cout << endl;
cout << "Pais invalido! Tente novamente: ";
getline(cin >> ws, pais);
cout << endl;
}
transform(pais.begin(), pais.end(), pais.begin(), ::toupper);
aeroportos_pais_v = aeroportos_pais(pais);
if(aeroportos_pais_v.size() < 5){
rnd = (int)(rand() % (aeroportos_pais_v.size() - 1 + 1)+1);
}
else{
rnd = (rand() % (5 - 3 + 1) + 3);
}
contador_companhias_pais = 0;
for(const auto& c : lfile.getCompanhias()){
batata = c.second.getPais();
transform(batata.begin(), batata.end(), batata.begin(), ::toupper);
if(batata == pais){
contador_companhias_pais++;
}
}
cont_partida_voos = 0;
cont_chegada_voos = 0;
cont_voos_chegada_temp = 0;
cont_voos_partida_temp = 0;
voos_por_aeroporto_v.clear();
for(const auto& a : aero_codigo_temp){
for(const auto& v : lfile.getChegadaPartidaCompanhia()){
if(v.first.first == a){
cont_partida_voos++;
cont_voos_partida_temp++;
}
if(v.first.second == a){
cont_chegada_voos++;
cont_voos_chegada_temp++;
}
}
voos_por_aeroporto_v.emplace_back(a,cont_chegada_voos + cont_partida_voos);
cont_partida_voos = 0;
cont_chegada_voos = 0;
}
sort(voos_por_aeroporto_v.begin(), voos_por_aeroporto_v.end(), [](const pair<string, int>& a, const pair<string , int>& b) {return a.second > b.second;});
clearScreen();
cout << "===========================================================" << endl;
cout << "|--------------------- ESTATISTICAS ----------------------|" << endl;
cout << "| Pais |" << endl;
cout << "|=========================================================|" << endl;
cout << " " << endl;
cout << " Pais - " << pais << " " << endl;
cout << " Existem " << aeroportos_pais_v.size() << " Aeroportos " << endl;
cout << " Existem " << contador_companhias_pais << " companhias de " << pais <<" " << endl;
cout << " Partem " << cont_voos_partida_temp << " voos de " << pais << " " << endl;
cout << " Chegam " << cont_voos_chegada_temp << " voos a " << pais << " " << endl;
cout << endl;
cout << " Top " << rnd << " Aeroportos com mais voos: " << endl;
for(int i = 0; i < rnd; i++) {
cout << " " << i+1 << " -> "
<< lfile.getAeroportos().find(lfile.getAeroportosCodigos().find(voos_por_aeroporto_v[i].first)->second)->second.getNome() << ", "
<< " - " << voos_por_aeroporto_v[i].second << endl;
}
cout << "| |" << endl;
cout << "===========================================================" << endl;
cout << endl;
voos_por_aeroporto_v.clear();
aeroportos_pais_v.clear();