-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
3091 lines (2287 loc) · 151 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
//da fare: levare i controlli in tutte le funzioni, i controlli voglio farli direttamente a inizio programma
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <utility>
#include "social.h"
#include "menu.h"
#include "tree.h"
ostream &operator<<(ostream &vout, const vector<string> &to_print) {
if (!to_print.empty()) {
for (int i = 0; i < to_print.size() - 1; ++i) {
vout << to_print[i] << ",";
}
vout << to_print.at(to_print.size() - 1);
}
return vout;
}
const char *characters = "/qwertyuiopasdfghjklzxcvbnm-.,_:;><|\tQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
/**Here i overload the operator<< for likes***/
using namespace std;
int main(int argc, char *argv[]) {
cout<<"Testing UTF-8"<<endl;
cout << LIKE << DISLIKE;
Menu menu1;
menu1.SetLogo("logo.txt");
menu1.SetUserFile("users.dat");
menu1.SetReletionFile("relations.dat");
menu1.SetPostFile("posts.dat");
string file_name = menu1.GetUserFile();
vector<string> Utentii;
vector<string> groups_usernames;
vector<string> company_usernames;
Utentii = getUsers("users.dat");
groups_usernames = getGroups("users.dat");
company_usernames = getCompanies("users.dat");
vector<string> postatori;
postatori = PostingPeople("posts.dat");
vector<User> Userss(Utentii.size());
vector<Company> CompanyObj(company_usernames.size());
vector<Group> Groups(groups_usernames.size());
/***************************************************************************/
for (int i = 0; i < Userss.size(); i++) {
Userss[i].setFileRef("users.dat");
Userss[i].setUsername(Utentii[i]);
Userss[i].setRelFileRef(menu1.GetRelationFile());
Userss[i].setPostsFileRef(menu1.GetPostFile());
Userss[i].setDate();
Userss[i].setDays();
Userss[i].setName();
Userss[i].setCity();
Userss[i].setAge();
Userss[i].setRelations();
Userss[i].loadPosts();
Userss[i].setSurname();
Userss[i].setCity();
Userss[i].setUniversity();
Userss[i].setReligion();
Userss[i].setSex();
Userss[i].setParty();
}
for (int i = 0; i < Groups.size(); i++) {
Groups[i].setFileRef(menu1.GetUserFile());
Groups[i].setPostsFileRef(menu1.GetPostFile());
Groups[i].setRelFileRef("relations.dat");
Groups[i].setUsername(groups_usernames[i]);
Groups[i].setName();
Groups[i].SetComponents();
Groups[i].loadPosts();
Groups[i].SetHeadquarter();
Groups[i].SetField();
Groups[i].setDate();
}
for (int i = 0; i < CompanyObj.size(); i++) {
CompanyObj[i].setFileRef(menu1.GetUserFile());
CompanyObj[i].setPostsFileRef(menu1.GetPostFile());
CompanyObj[i].setRelFileRef("relations.dat");
CompanyObj[i].setUsername(company_usernames[i]);
CompanyObj[i].setName();
CompanyObj[i].SetEmployees();
CompanyObj[i].SetSubsidiary();
CompanyObj[i].loadPosts();
CompanyObj[i].setDate();
CompanyObj[i].SetCode();
CompanyObj[i].SetHeadquarter();
CompanyObj[i].SetTaxOffice();
CompanyObj[i].SetField();
//cout<<CompanyObj[i].GetEmployees();
}
vector<User>::iterator it;
vector<string>::iterator s;
Person *treecomp[Userss.size()];
int indxe;
indxe = 0;
for (it = Userss.begin(); it != Userss.end(); it++) {
Person *_to_add = new Person(it->getUsername());
_to_add->setFather(NULL);
_to_add->setMother(NULL);
treecomp[indxe] = _to_add;
indxe++;
}
cout << "stampo le persone" << endl;
for (int indxe = 0; indxe < Userss.size(); indxe++) {
cout << treecomp[indxe]->getName() << endl;
}
cout << "ho finito di stampare le persone" << endl;
indxe = 0;
for (it = Userss.begin(); it != Userss.end(); it++) {
if (!it->GetMother().empty()) {
int pos = getVecPos(it->GetMother(), Utentii);
treecomp[indxe]->setMother(treecomp[pos]);
}
if (!it->GetFather().empty()) {
int pos = getVecPos(it->GetFather(), Utentii);
treecomp[indxe]->setFather(treecomp[pos]);
}
indxe++;
}
indxe = 0;
while (indxe < Utentii.size()) {
cout << "Utente " << treecomp[indxe]->getName() << " ha padre ->";
treecomp[indxe]->printFather();
cout << "Utente " << treecomp[indxe]->getName() << " ha madre ->";
treecomp[indxe]->printMother();
//cout<<endl<<treecomp[indxe]->getFather();
indxe++;
}
cout << endl;
treecomp[1]->printTree(treecomp[1], 5);
//cout<<treecomp[1]->getFather()->getName();
cout << endl;
cout << "********************************************" << endl;
cout << CompanyObj[0].getName() << "------>" << CompanyObj[0].GetEmployees();
cout << CompanyObj[1].getName() << "------>" << CompanyObj[1].GetEmployees();
cout << CompanyObj[0].getName() << "------>" << CompanyObj[2].GetEmployees();
// initObj(gruppi);
cout << "amici di " << Userss[0].getName() << endl;
cout << Userss[0].getSurname();
menu1.welcomeScreen();
/*** If menu1.GetPos<0 ----> exit while loop ***/
while (menu1.GetPos() > 0) {
int n_space = 0;
string command;
string argument;
string ins = menu1.getQuery();
string insert;
for (char in : ins) { /** removing the lasts spaces using a range based loop **/
if (in == ' ') {
n_space++;
} else { n_space = 0; }
}
insert = ins.substr(0, ins.length() - n_space);
if (isalnum(insert.at(0))) {
command = insert.substr(0, insert.find(' ', 0));
if (insert.find_first_not_of(' ', command.length()) != string::npos) {
unsigned long start, end;
start = insert.find_first_not_of(' ', command.length());
end = insert.find_first_not_of(characters, command.length() + 1);
argument = insert.substr(start, end - start);
} else { argument = ""; }
}
/*** Now i have a command and a argument ***/
switch (menu1.GetPos()) {
case START_MENU:
if (command == "statistiche") {
menu1.SetPos(STATS_MENU);
helpScreen(menu1.GetPos());
} else if (command == "gestioneutenti") {
menu1.SetPos(MANAGER_MENU);
helpScreen(menu1.GetPos());
} else if (command == "alberi") {
helpScreen(menu1.GetPos());
Menu *mtree = new Menu;
mtree->SetPos(FAMILY_TREE);
string ans;
while (mtree->GetPos() > 0) {
cout << "Immetti il nome dell' utente di cui vuoi l' albero, digita exit per uscire " << endl
<< endl;
ans = mtree->getQuery();
if (ans == "exit") {
mtree->SetPos(EXIT_MENU);
} else {
if (common(ans, Utentii)) {
cout << "Stampo l'albero di" << ans << endl;
int pos = getVecPos(ans, Utentii);
cout << endl << endl;
treecomp[pos]->printTree(treecomp[pos], 2);
cout << endl << endl;
} else { cout << "Errore di immissione" << endl; }
}
}
delete mtree;
} else if (command == "simpatia") {
menu1.SetPos(BEST_COMPANY);
helpScreen(menu1.GetPos());
} else if (command == "gestionerelazioni") {
menu1.SetPos(RELATION_MENU);
helpScreen(menu1.GetPos());
} else if (command == "gestionenotizie") {
menu1.SetPos(POST_MENU);
helpScreen(menu1.GetPos());
} else if (command == "start") {
menu1.SetPos(START_MENU);
} else if (command == "help") {
} else if (command == "solitari") {
cout << "Sei entrato nel menu di ricerca lupi solitari" << endl;
cout
<< "Devi prima definire dei parametri di lupo solitario, in base al numero di relazioni con altri utenti,"
<< " l’appartenenza a gruppi, l’essere o meno dipendenti di una azienda ed al numero di apprezzamenti sulle news"
<< endl << endl;
cout << endl
<< "Una volta terminato l' inserimento, digita exit per uscire e visualizzare il risultato"
<< endl << endl;
Menu *ms = new Menu;
ms->SetSubMenu('Y');
ms->SetPos(QUIET_USERS_MENU);
/*Minimal relation and iteration number to not be considered "lone wolf"*/
int rel_num = 0;
int interation_num = 0;
/*Need to know if is relevant to be in a group or company to not be considered "lone wolf"*/
bool in_group = false;
bool in_company = false;
/*By default no one is a lonely user*/
vector<string> _insertion;
helpScreen(ms->GetPos());
while (ms->GetPos() > 0) {
cout << endl;
cout << "Numero relazioni minime: " << rel_num << endl;
cout << "Numero apprezzamenti minimi: " << interation_num << endl;
cout << "Appartenenza a gruppi impostato: " << in_group << endl;
cout << "Appartenenza ad aziende impostato: " << in_company << endl;
_insertion = ms->subQuery();
if (_insertion.size() == 2) {
if (_insertion[0] == "gruppi") {
if (_insertion[1] == "SI") { in_group = true; }
else if (_insertion[1] == "NO") { in_group = false; }
else { cout << "Errore di immissione" << endl; }
} else if (_insertion[0] == "aziende") {
if (_insertion[1] == "SI") { in_company = true; }
else if (_insertion[1] == "NO") { in_company = false; }
else { cout << "Errore di immissione" << endl; }
} else if (_insertion[0] == "relazioni") {
if (isnumerical(_insertion[1])) {
rel_num = stoi(_insertion[1]);
} else { cout << "Errore di immissione" << endl; }
} else if (_insertion[0] == "apprezzamenti") {
if (isnumerical(_insertion[1])) {
interation_num = stoi(_insertion[1]);
} else { cout << "Errore di immissione" << endl; }
}
} else { cout << "Errore di immissione" << endl; }
}/*Now that you exited the program have to print the quiet users*/
delete ms;/*deleting menu*/
cout << "Adesso stampo i forever alone" << endl;
vector<User> QuietUsers = Userss;/*first i copy all Users, after the program delete the not quiets*/
vector<string> quiet_usernames = Utentii;
vector<string> people_to_erase;
if (in_group) {
/*If be part of a group is required to not be a quiet user, the program will delete anyone who is not in a group*/
for (int i = 0; i < Groups.size(); i++) {
vector<string> _components;
_components = Groups[i].GetComponents();
people_to_erase.insert(people_to_erase.end(), _components.begin(), _components.end());
}
}
/************************ Make order **************************/
sort(people_to_erase.begin(), people_to_erase.end());
people_to_erase.erase(unique(people_to_erase.begin(), people_to_erase.end()),
people_to_erase.end());
/*************************************************************/
if (in_company) {
/*If be part of a company is required to not be a quiet user, the program will delete anyone who is not in a company*/
for (int i = 0; i < CompanyObj.size(); i++) {
vector<string> _employees;
_employees = Groups[i].GetComponents();
people_to_erase.insert(people_to_erase.end(), _employees.begin(), _employees.end());
}
}
/******************* Make Order **************************/
sort(people_to_erase.begin(), people_to_erase.end());
people_to_erase.erase(unique(people_to_erase.begin(), people_to_erase.end()),
people_to_erase.end());
/********************************************************/
/*Now likes and dislikes*/
/*first load all posts*/
if (interation_num >= 0) {
vector<Post> AllPosts;
for (int i = 0; i < Userss.size(); i++) {
vector<Post> user_posts = Userss[i].getPost();
AllPosts.insert(AllPosts.end(), user_posts.begin(), user_posts.end());
}
for (int i = 0; i < CompanyObj.size(); i++) {
vector<Post> user_posts = CompanyObj[i].getPost();
AllPosts.insert(AllPosts.end(), user_posts.begin(), user_posts.end());
}
for (int i = 0; i < Groups.size(); i++) {
vector<Post> user_posts = Groups[i].getPost();
AllPosts.insert(AllPosts.end(), user_posts.begin(), user_posts.end());
}
/*now store all likes and dislikes in a single vector, couting after the total number of appreciations*/
vector<string> AllAppreciations;
for (int i = 0; i < AllPosts.size(); i++) {
AllAppreciations.insert(AllAppreciations.end(), AllPosts[i].likes.begin(),
AllPosts[i].likes.end());
AllAppreciations.insert(AllAppreciations.end(), AllPosts[i].dislikes.begin(),
AllPosts[i].dislikes.end());
}
sort(AllAppreciations.begin(), AllAppreciations.end());
/*Now the program check the number of likes+dislikes for each user who liked or disliked a post*/
/* In program it is equal to store in a vector of pairs likes+disliked plus the relative username*/
vector<pair<int, string>> ApprAndUser;
ApprAndUser = occurr(AllAppreciations);
/*Now the program check interations>treshold*/
/*Remember that all users is supposed to be quiet users, but if they have sum> treshold they are "safe"*/
for (int i = 0; i < ApprAndUser.size(); i++) {
if (ApprAndUser[i].first > interation_num) {
people_to_erase.emplace_back(ApprAndUser[i].second);
}
}
}
/*Now check the relations*/
if (rel_num >= 0) {
/*This vector stores all users[i]'s relations whit relative relations finded (friends, knowed_people, parents,mate and sons)*/
auto *AllUserWithRelations = new vector<pair<string, vector<string>>>;
vector<User>::iterator it;
for (it = Userss.begin(); it != Userss.end(); it++) {
vector<string> all_relations;
vector<string> knowed;
knowed = it->GetKnowed();
all_relations.insert(all_relations.end(), knowed.begin(), knowed.end());
vector<string> friends;
friends = it->GetFriends();
all_relations.insert(all_relations.end(), friends.begin(), friends.end());
vector<string> sons;
sons = it->GetSons();
all_relations.insert(all_relations.end(), sons.begin(), sons.end());
all_relations.emplace_back(it->GetFather());
all_relations.emplace_back(it->GetMother());
all_relations.emplace_back(it->GetMate());
/*Now remove possible void string*/
all_relations.erase(remove_if(all_relations.begin(), all_relations.end(), isVoid),
all_relations.end());
AllUserWithRelations->emplace_back(make_pair(it->getUsername(), all_relations));
}
/*Now the program "shrink" AllUserWithRelations' vector<string> into a number and make a pair with relative user_name*/
/******************************************************************************************************/
vector<pair<int, string>> AllRelationsNum;/*first is relations' number, second is the pos in Userss*/
/******************************************************************************************************/
vector<pair<string, vector<string>>>::iterator iter;
for (iter = AllUserWithRelations->begin(); iter != AllUserWithRelations->end(); iter++) {
AllRelationsNum.emplace_back(make_pair(iter->second.size(), iter->first));
}
delete AllUserWithRelations;
/*Now the program have a vector of pair with the number of relations and the relative usernames*/
/*The user[i] with a nuberofrelation>threshold will be eliminated from the list of quiet users*/
/* Everything from relation is now stored in AllRelationsNum*/
vector<pair<int, string>>::iterator iterator1;
for (iterator1 = AllRelationsNum.begin(); iterator1 != AllRelationsNum.end(); iterator1++) {
if (iterator1->first > rel_num) {
people_to_erase.emplace_back(iterator1->second);
}
}
}
/*Now all user that respect the thresholds are in a list that exclude them from the quiet users list*/
/*removing duplicates from people_to_erase*/
sort(people_to_erase.begin(), people_to_erase.end());
people_to_erase.erase(unique(people_to_erase.begin(), people_to_erase.end()),
people_to_erase.end());
/*now get positions and erase the not quiet users */
for (int i = 0; i < people_to_erase.size(); i++) {
auto pos = getVecPos(people_to_erase[i], quiet_usernames);
QuietUsers.erase(QuietUsers.begin() + pos);
quiet_usernames.erase(quiet_usernames.begin() + pos);
}
/* End operations, now print */
cout << "Ecco gli utenti solitari secondo i parametri immessi" << endl << endl;
showSUser(QuietUsers);
} else if (command == "mostrautenti") {
showSUser(Userss);
showCUser(CompanyObj);
showGUser(Groups);
} else {
cerr << "Comando Sconosciuto" << endl;
}
break;
case STATS_MENU:
if (!isStatsCmd(command)) {
cerr << "Comando Sconosciuto" << endl;
}
if (command == "start") {
menu1.SetPos(START_MENU);
}
if (command == "tot") {
if (argument.empty()) {
cout << "Il numero totale di utenti è "
<< numS(menu1.GetUserFile()) + numC(menu1.GetUserFile()) + numG(menu1.GetUserFile())
<< endl;
cout << "Utenti Semplici: " << numS(menu1.GetUserFile()) << endl;
cout << "Utenti Azienda: " << numC(menu1.GetUserFile()) << endl;
cout << "Utenti Gruppo: " << numG(menu1.GetUserFile()) << endl;
} else if (argument == "S" || argument == "s") {
cout << "Utenti Semplici: " << numS(menu1.GetUserFile()) << endl;
} else if (argument == "A" || argument == "a") {
cout << "Utenti Azienda: " << numC(menu1.GetUserFile()) << endl;
} else if (argument == "G" || argument == "g") {
cout << "Utenti Gruppo: " << numG(menu1.GetUserFile()) << endl;
} else {
cout << "Errore di immissione parametro: parametro sconosciuto [" << argument << "]" << endl;
}
}
if (command == "nsince") {
if (!argument.empty()) {
int days = daysByDate(argument);
if (isDateCorrect(argument)) {
if (days >= 0) {
int count = 0;
for (int i = 0; i < Userss.size(); i++) {
if (Userss[i].getDays() < days) {
count++;
}
}
cout << "Dopo il " << argument << " sono nati " << count << " utenti" << endl;
} else { cout << "Hai inserito una data del futuro" << endl; }
} else {
cout << "Errore di immissione parametro: Hai inserito una data in un formato scorretto"
<< endl;
}
} else {
cerr << "Errore di immissione parametro: Devi inserire una data nel formato GG/MM/YYYY" << endl;
}
}
if (command + argument == "ndipendenti" + argument) {
if (common(argument, company_usernames)) {
unsigned long pos = 0;
pos = getVecPos(argument, company_usernames);
cout << endl << "L' azienda @" << CompanyObj[pos].getUsername() << " con nome: "
<< CompanyObj[pos].getName() << " ha " << CompanyObj[pos].GetNEmployees() << " dipendenti"
<< endl;
} else if (argument.empty()) {
cout << "Non hai inserito un username, stampo tutte le info trovate" << endl << endl;
unsigned long pos = 0;
for (pos = 0; pos < CompanyObj.size(); pos++) {
cout << "L' azienda @" << CompanyObj[pos].getUsername() << " con nome: "
<< CompanyObj[pos].getName() << " ha " << CompanyObj[pos].GetNEmployees()
<< " dipendenti"
<< endl;
}
} else {
cerr << "Errore di immissione parametro: Azienda inesistente" << endl;
}
}
if (command + argument == "nconsociate" + argument) {
if (common(argument, company_usernames)) {
unsigned long pos = 0;
pos = getVecPos(argument, company_usernames);
cout << endl << "L' azienda @" << CompanyObj[pos].getUsername() << " con nome: "
<< CompanyObj[pos].getName() << " ha " << CompanyObj[pos].GetNSubsidiary() << " consociate"
<< endl;
} else if (argument.empty()) {
cout << "Non hai inserito un username, stampo tutte le info trovate" << endl << endl;
unsigned long pos = 0;
for (pos = 0; pos < CompanyObj.size(); pos++) {
cout << "L' azienda @" << CompanyObj[pos].getUsername() << " con nome: "
<< CompanyObj[pos].getName() << " ha " << CompanyObj[pos].GetNSubsidiary()
<< " consociate"
<< endl;
}
} else {
cerr << "Errore di immissione parametro: Azienda inesistente" << endl;
}
}
if (command + argument == "ncomponenti" + argument) {
if (argument.empty()) {
cout << "Gruppi e componenti:" << endl;
for (unsigned int i = 0; i < Groups.size(); i++) {
cout << "Gruppo con nome: " << Groups[i].getName() << ", username: @"
<< Groups[i].getUsername() << " ha " << Groups[i].GetNComponents() << " componenti"
<< endl;
}
} else if (common(argument, groups_usernames)) {
cout << "Gruppi e componenti:" << endl;
for (unsigned int i = 0; i < Groups.size(); i++) {
if (Groups[i].getUsername() == argument and !argument.empty()) {
cout << "Gruppo con nome: " << Groups[i].getName() << ", username: @"
<< Groups[i].getUsername() << " ha " << Groups[i].GetNComponents() << " componenti"
<< endl;
}
}
} else { cerr << "Errore di immissione parametro: Gruppo inesistente" << endl; }
}
if (command + argument == "maxdipendenti" + argument) {
if (argument == "S") {
unsigned long max = 0;
for (int i = 0; i < CompanyObj.size(); i++) {
if (CompanyObj[i].GetNEmployees() > max) {
max = CompanyObj[i].GetNEmployees();
}
}
cout << endl << endl;
if (max != 0) {
for (auto &i : CompanyObj) {
if (i.GetNEmployees() == max) {
cout << "Azienda con nome " << i.getName()
<< " ha il numero più grande di dipendenti: "
<< i.GetNEmployees() << " dipendenti" << endl;
}
}
}
} else if (argument == "C") {
unsigned long max = 0;
vector<int> max_poss; /**Where are the max cumulative employees*/
vector<string> cumulative;
for (int i = 0; i < CompanyObj.size(); i++) {
cumulative = CompanyObj[i].GetEmployees();
if (CompanyObj[i].GetNSubsidiary() > 0) {
vector<string> subsidiaries;
subsidiaries = CompanyObj[i].GetSubsidiary();
vector<int> com_pos; /*Store the positions of the subsidiary*/
for (int j = 0; j < subsidiaries.size(); j++) {
com_pos.emplace_back(getVecPos(subsidiaries[j], company_usernames));
}
for (int k = 0; k < com_pos.size(); k++) {
vector<string> employees_to_add = CompanyObj[com_pos[k]].GetEmployees();
cumulative.insert(cumulative.end(), employees_to_add.begin(),
employees_to_add.end());
}
}
sort(cumulative.begin(),
cumulative.end()); /*** Now i remove possible double employees (cause a person can work both for two affiliated companies) ***/
auto last = unique(cumulative.begin(), cumulative.end());
cumulative.erase(last, cumulative.end());
if (cumulative.size() > max) {
max_poss.clear();
max = cumulative.size();
max_poss.emplace_back(i);
} else if (cumulative.size() == max) {
max_poss.emplace_back(i);
}
}
cout << "Aziende con il più alto numero di dipendenti cumulativi:" << endl;
for (int h = 0; h < max_poss.size(); h++) {
cout << "@" << CompanyObj[max_poss[h]].getUsername() << ", Azienda con nome:"
<< CompanyObj[max_poss[h]].getName() << ", ha " << max << " dipendenti" << endl;
}
cout << endl;
} else { cerr << "Errore di immissione parametro" << endl; }
}
if (command == "mostLiked") {
/************ Creating a list of posting people,groups,companies ***************************************/
vector<string> posting_usernames;
for (int i = 0; i < Userss.size(); i++) {
if (Userss[i].GetNPosts() > 0) {
posting_usernames.emplace_back(Userss[i].getUsername());
}
}
for (int i = 0; i < CompanyObj.size(); i++) {
if (CompanyObj[i].GetNPosts() > 0) {
posting_usernames.emplace_back(CompanyObj[i].getUsername());
}
}
for (int i = 0; i < Groups.size(); i++) {
if (Groups[i].GetNPosts() > 0) {
posting_usernames.emplace_back(Groups[i].getUsername());
}
}
vector<gUser> postingObjs(posting_usernames.size());
for (int i = 0; i < postingObjs.size(); i++) {
postingObjs[i].setUsername(posting_usernames[i]);
}
vector<vector<Post> > tutti_i_post;
int user_no = 0;
for (user_no = 0; user_no < postingObjs.size(); user_no++) {
if (common(postingObjs[user_no].getUsername(), Utentii)) {
/**I need to copy vector<post> in the new list**/
long obj_pos = getVecPos(postingObjs[user_no].getUsername(), Utentii);
postingObjs[user_no].loadPosts(Userss[obj_pos].getPost());
}
if (common(postingObjs[user_no].getUsername(), company_usernames)) {
/**I need to copy vector<post> in the new list**/
long obj_pos = getVecPos(postingObjs[user_no].getUsername(), company_usernames);
postingObjs[user_no].loadPosts(CompanyObj[obj_pos].getPost());
}
if (common(postingObjs[user_no].getUsername(), groups_usernames)) {
/**I need to copy vector<post> in the new list**/
long obj_pos = getVecPos(postingObjs[user_no].getUsername(), groups_usernames);
postingObjs[user_no].loadPosts(Groups[obj_pos].getPost());
}
/*** Posts loaded in the generic list of posting objs****/
}
for (user_no = 0; user_no < postingObjs.size(); user_no++) {
tutti_i_post.emplace_back(postingObjs[user_no].getPost());
}
unsigned long nLmax = 0;
vector<string> message;
vector<string> username;
vector<int> post_n;
vector<int> user_n;
if (argument.empty()) {
for (user_no = 0; user_no < tutti_i_post.size(); user_no++) {
for (int post_no = 0; post_no < (postingObjs[user_no].getPost()).size(); post_no++) {
if (tutti_i_post[user_no][post_no].likes.size() > nLmax) {
message.clear();
post_n.clear();
user_n.clear();
username.clear();
nLmax = tutti_i_post[user_no][post_no].likes.size();
message.emplace_back(tutti_i_post[user_no][post_no].message);
user_n.push_back(user_no);
post_n.push_back(post_no);
username.emplace_back(tutti_i_post[user_no][post_no].username);
} else if (tutti_i_post[user_no][post_no].likes.size() == nLmax) {
nLmax = tutti_i_post[user_no][post_no].likes.size();
message.emplace_back(tutti_i_post[user_no][post_no].message);
user_n.push_back(user_no);
post_n.push_back(post_no);
username.emplace_back(tutti_i_post[user_no][post_no].username);
}
}
}
cout << "I post con più likes sono i seguenti" << endl;
} else if (!argument.empty() and common(command, posting_usernames)) {
for (user_no = 0; user_no < tutti_i_post.size(); user_no++) {
for (int post_no = 0; post_no < (postingObjs[user_no].getPost()).size(); post_no++) {
if (tutti_i_post[user_no][post_no].username == command and
tutti_i_post[user_no][post_no].likes.size() == nLmax) {
message.emplace_back(tutti_i_post[user_no][post_no].message);
user_n.push_back(user_no);
post_n.push_back(post_no);
username.emplace_back(tutti_i_post[user_no][post_no].username);
} else if (tutti_i_post[user_no][post_no].username == command and
tutti_i_post[user_no][post_no].likes.size() > nLmax) {
message.clear();
post_n.clear();
user_n.clear();
username.clear();
nLmax = tutti_i_post[user_no][post_no].likes.size();
message.emplace_back(tutti_i_post[user_no][post_no].message);
user_n.push_back(user_no);
post_n.push_back(post_no);
username.emplace_back(tutti_i_post[user_no][post_no].username);
}
}
}
cout << "I post con più likes scritti da " << command << " sono i seguenti" << endl;
}
/** Now print **/
for (int i = 0; i < username.size(); i++) {
cout << message[i] << " scritto da @" << username[i] << " con un totale di " << nLmax
<< " Likes" << endl;
}
/*******************************************************************************************/
}
if (command == "mostDisliked") {
vector<string> posting_usernames;
for (int i = 0; i < Userss.size(); i++) {
if (Userss[i].GetNPosts() > 0) {
posting_usernames.emplace_back(Userss[i].getUsername());
}
}
for (int i = 0; i < CompanyObj.size(); i++) {
if (CompanyObj[i].GetNPosts() > 0) {
posting_usernames.emplace_back(CompanyObj[i].getUsername());
}
}
for (int i = 0; i < Groups.size(); i++) {
if (Groups[i].GetNPosts() > 0) {
posting_usernames.emplace_back(Groups[i].getUsername());
}
}
vector<gUser> postingObjs(posting_usernames.size());
for (int i = 0; i < postingObjs.size(); i++) {
postingObjs[i].setUsername(posting_usernames[i]);
}
vector<vector<Post> > tutti_i_post;
int user_no = 0;
for (user_no = 0; user_no < postingObjs.size(); user_no++) {
if (common(postingObjs[user_no].getUsername(), Utentii)) {
/**I need to copy vector<post> in the new list**/
long obj_pos = getVecPos(postingObjs[user_no].getUsername(), Utentii);
postingObjs[user_no].loadPosts(Userss[obj_pos].getPost());
}
if (common(postingObjs[user_no].getUsername(), company_usernames)) {
/**I need to copy vector<post> in the new list**/
long obj_pos = getVecPos(postingObjs[user_no].getUsername(), company_usernames);
postingObjs[user_no].loadPosts(CompanyObj[obj_pos].getPost());
}
if (common(postingObjs[user_no].getUsername(), groups_usernames)) {
/**I need to copy vector<post> in the new list**/
long obj_pos = getVecPos(postingObjs[user_no].getUsername(), groups_usernames);
postingObjs[user_no].loadPosts(Groups[obj_pos].getPost());
}
/*** Posts loaded in the generic list of posting objs****/
}
for (user_no = 0; user_no < postingObjs.size(); user_no++) {
tutti_i_post.emplace_back(postingObjs[user_no].getPost());
}
unsigned long nDmax = 0;
vector<string> message;
vector<string> username;
vector<int> post_n;
vector<int> user_n;
if (argument.empty()) {
for (user_no = 0; user_no < tutti_i_post.size(); user_no++) {
for (int post_no = 0; post_no < (postingObjs[user_no].getPost()).size(); post_no++) {
if (tutti_i_post[user_no][post_no].dislikes.size() > nDmax) {
message.clear();
post_n.clear();
user_n.clear();
username.clear();