-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainCppFile.cpp
More file actions
674 lines (617 loc) · 23.1 KB
/
mainCppFile.cpp
File metadata and controls
674 lines (617 loc) · 23.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
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
// offline question and answer platform
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <windows.h>
#include "feeds.h" // display the feeds of the users
#include "UserProfile.h" // play with user profile
#include "recommendation.h" // recommend users
#include "hands.h"
#include "AddingPost.h"
#include "allUsers.h"
#include "loginregister.h"
// colors
#define RESET "\033[0m"
#define RED "\033[1;31m"
#define GREEN "\033[1;32m"
#define YELLOW "\033[1;33m"
#define BLUE "\033[1;34m"
#define MAGENTA "\033[1;35m"
#define CYAN "\033[1;36m"
// font size
#define LARGER "\033[1m"
#define NORMAL "\033[0m"
using namespace std;
void MainDashboard(void); // dispklay the main dashboard
void showProfile(void); // show the user profile
void update(Profile &N, string current_user); // upate the user profile
void showFeed(string user); // show feed
void Recommend(string user); // Recommend use for search
void AddPost(Profile &N, string user); // adding post
void search(string); // Search user
void displayDetails(string user, string currentUser); // display user profile
string login_register(); // all login related things
void noFollowingdisconnectedvertex(void);
void mutual(string user, string currentUser);
void followUser(string current,string currentUser);
int main(void)
{
string current_user = login_register();
if (current_user.length() == 0)
{
return 0;
}
int choice;
Profile N;
int flag = 0;
N.getDetails(current_user);
do
{
system("cls");
MainDashboard();
cout << endl;
cout << "\t\t\t\t\t" << GREEN << "Enter Your choice: " << RESET;
cin >> choice;
switch (choice)
{
case 1: // profile
system("cls");
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "Profile" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << endl;
cout << "\t\t\t\t\t1." << YELLOW << "View Profile" << RESET << endl;
cout << "\t\t\t\t\t2." << YELLOW << "Update Profile" << RESET << endl;
cout << "\t\t\t\t\t" << CYAN << "Enter 0 to go back: " << RESET << endl
<< endl;
cout << "\t\t\t\t\t" << GREEN << "Enter Your choice: " << RESET;
int profile_choice;
cin >> profile_choice;
while (true)
{
if (profile_choice == 1)
{
system("cls");
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "User Details" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
N.display();
cout << endl
<< endl;
cout << "\t\t\t\t" << GREEN << "(Press 0 to go back)" << RESET;
}
else if (profile_choice == 2)
{
update(N, current_user);
cout << "\t\t\t\t" << GREEN << "(Press 0 to go back)" << RESET;
}
else if (profile_choice == 0)
{
break;
}
else
{
cout << "Invalid Input!";
}
cin >> profile_choice;
}
break;
case 2: // searching
system("cls");
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "Searching" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\t1." << YELLOW << "Search People" << RESET << endl;
cout << "\t\t\t\t\t2." << YELLOW << "Recommendation" << RESET << endl;
cout << "\t\t\t\t\t" << CYAN << "Enter 0 to go back: " << RESET << endl
<< endl;
cout << "\t\t\t\t\t" << GREEN << "Enter Your choice: " << RESET;
int ch;
cin >> ch;
while (true)
{
// cin >> ch;
if (ch == 1)
{
search(current_user);
// break;
cout << GREEN << "\t\t\t\t(Press 0 to go back) " << RESET;
}
else if (ch == 2)
{
Recommend(current_user);
// break;
cout << GREEN << "(Press 0 to go back) " << RESET;
}
else if (ch == 0)
{
break;
}
else
{
cout << RED << "Invalid Input" << RESET;
}
cin >> ch;
}
break;
case 3: // adding posts
system("cls");
AddPost(N, current_user);
break;
case 4: // show the feeds
system("cls");
showFeed(current_user);
break;
case 5: // settings
system("cls");
int ch1;
while (true)
{
cout << RED << "1. Log out" << RESET << endl;
cout << GREEN << "(Press 0 to go back )" << RESET << endl;
cin >> ch1;
if (ch1 == 1)
{
flag++;
break;
}
else if (ch1 == 0)
{
break;
}
else
{
cout << "Invalid Input";
}
}
break;
default:
cout << "Invalid choice";
cin >> choice;
break;
}
if (flag)
{
break;
}
} while (true); // Loop until user chooses to exit
return 0;
}
// add new post to feed
void AddPost(Profile &N, string user)
{
POST obj;
obj.ReadFeed();
string Id = obj.addingPost();
N.addPostToProfile(Id, user);
}
// display main dashboard
void MainDashboard(void)
{
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "Main Dashboard" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << endl;
cout << "\t\t\t\t\t1. " << YELLOW << "Your Profile" << RESET << endl;
cout << "\t\t\t\t\t2. " << YELLOW << "Search People" << RESET << endl;
cout << "\t\t\t\t\t3. " << YELLOW << "Add Post" << RESET << endl;
cout << "\t\t\t\t\t4. " << YELLOW << "Show Feeds" << RESET << endl;
cout << "\t\t\t\t\t5. " << RED << "Settings" << RESET << endl;
}
// register and login
string login_register()
{
system("cls");
int choice;
string a;
do
{
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* Q&A PLATFORM *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << endl;
cout << "\t\t\t\t\t\033[1;33m1. Login\033[0m" << endl;
cout << "\t\t\t\t\t\033[1;33m2. Sign up\033[0m" << endl;
cout << "\t\t\t\t\t\033[1;33m3. Exit\033[0m" << endl;
cout << endl;
cout << "\t\t\t\t\t\033[1;32mEnter your choice: \033[0m";
cin >> choice;
page p;
if (choice == 1)
{
cout << "Loading LOGIN page" << endl;
Sleep(1000);
a = p.login();
if (a.length() != 0)
break;
}
else if (choice == 2)
{
cout << "Loading SIGN-UP page" << endl;
Sleep(1000);
p.signup();
}
else if (choice == 3)
{
cout << "Exiting the program. Goodbye!" << endl;
Sleep(2000);
}
else
{
cout << "\033[1;31mInvalid choice. Please try again.\033[0m" << endl;
}
} while (choice != 3);
return a;
}
// Searching user profile
void search(string currentUser)
{
system("cls");
SearchingPanel obj;
unordered_map<int, vector<string>> user;
user = obj.detailsToHashTable();
string c;
cout << YELLOW << "ENTER THE USERNAME TO SEARCH: " << endl
<< RESET;
cout << BLUE << ": " << RESET;
cin.ignore();
getline(cin, c);
if (obj.searchUser(c) == 1)
{
cout << "\t\t\t\t\t\t\t" << GREEN << "Enter the Username to Search: " << RESET;
displayDetails(c, currentUser);
}
else
{
cout << "User not found";
}
}
// display searched user profile
void displayDetails(string user, string currentUser)
{
system("cls");
cout << CYAN << "\t\t\t\t\t\t\tSearched User Details" << RESET << endl
<< endl;
string file = "registrationdata/" + user + ".txt";
string following, followers;
vector<string> words;
int i;
string word;
ifstream read(file);
const int columnWidth = 15;
cout << "\t\t\t\t\t\t\t+" << string(columnWidth * 2 + 10, '-') << "+" << endl;
if (read.is_open())
{
string str;
getline(read, str);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "Name"
<< "|" << left << setw(columnWidth) << str << "\t|" << endl;
getline(read, str);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "User Name"
<< "|" << left << setw(columnWidth) << str << "\t|" << endl;
getline(read, str);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "DOB"
<< "|" << left << setw(columnWidth) << str << "\t|" << endl;
getline(read, str);
getline(read, str);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "Profession"
<< "|" << left << setw(columnWidth) << str << "\t|" << endl;
getline(read, str);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "Description"
<< "|" << left << setw(columnWidth) << str << "\t|" << endl;
getline(read, str);
getline(read, following);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "Following"
<< "|" << left << setw(columnWidth) << str << "\t|" << endl;
// ------------------------------------------------
stringstream ss(following);
while(ss >> word)
{
words.push_back(word);
}
for(i=0 ; i<words.size() ; i++ ) {
if(words[i] == currentUser) {
mutual(user, currentUser);
break;
}
}
// ------------------------------------------------
getline(read, followers);
cout << "\t\t\t\t\t\t\t|" << left << setw(columnWidth) << "Followers"
<< "|" << left << setw(columnWidth) << followers << "\t|" << endl;
}
cout << "\t\t\t\t\t\t\t+" << string(columnWidth * 2 + 10, '-') << "+" << endl;
// -----------------------------------------------
if(i>=words.size()) {
cout<<"press 1 to follow and 0 to continue"<<endl;
int choice;
cin>>choice;
if(choice == 1) {
followUser(user,currentUser);
}
else if(choice == 0) {
return ;
}
}
// -----------------------------------------------
}
// all the followers and following to the current and searche user
void followUser(string user,string currUser) {
string name, username, dob, email, profession, description, password, followers, following, blog;
ifstream read;
read.open("registration/" + user + ".txt");
getline(read, name);
getline(read, username);
getline(read, dob);
getline(read, email);
getline(read, profession);
getline(read, description);
getline(read, password);
getline(read, following);
getline(read, followers);
getline(read, blog);
followers = currUser + followers;
read.close();
ofstream write;
write.open("registration/" + user + ".txt");
write<< name <<"\n" << username <<"\n" << dob <<"\n" <<email <<"\n" <<profession << "\n" <<description << "\n" << password << "\n" <<following << "\n" <<followers << "\n" << blog << "\n";
write.close();
read.open("registration/" + currUser + ".txt");
getline(read, name);
getline(read, username);
getline(read, dob);
getline(read, email);
getline(read, profession);
getline(read, description);
getline(read, password);
getline(read, following);
getline(read, followers);
getline(read, blog);
following = currUser + following;
read.close();
// ofstream write;
write.open("registration/" + currUser + ".txt");
write<< name <<"\n" << username <<"\n" << dob <<"\n" <<email <<"\n" <<profession << "\n" <<description << "\n" << password << "\n" <<following << "\n" <<followers << "\n" << blog << "\n";
write.close();
}
// display the mutual friend
void mutual(string user, string currentUser)
{
Recommendation obj;
vector<string> vertices;
string filename = "logindata.txt", str;
ifstream read;
read.open(filename);
while(!getline(read, str).eof())
{
vertices.push_back(str);
getline(read, str);
}
Graph mutual_graph(vertices);
for (const auto& user : vertices) {
// graph.addEdge(curr_user, user[0]);
string curr = user;
vector<string> temp = obj.getFollowingInfo(("registrationdata/" + user + ".txt"));
for (int i = 0; i < temp.size(); i++) {
mutual_graph.addEdge(curr, temp[i]);
}
}
mutual_graph.displayCommonVertices(user, currentUser);
}
// shows the feeds
void showFeed(string user)
{
FEEDS obj;
obj.ReadFeed();
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "FEEDS" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
obj.displayNext();
char choice;
cout << GREEN << "Press D to go forward : Press A to fo backward (Press 0 to go back)" << RESET << endl;
cin >> choice;
choice = tolower(choice);
while (choice != '0')
{
system("cls");
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "FEEDS" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << endl;
if (choice == 'd')
{
obj.displayNext();
if (obj.isAnswerGiven() == 0)
{
cout << GREEN << "Want to answer(Press: Y/N): " << RESET;
cin >> choice;
cin.ignore();
cout << choice;
choice = tolower(choice);
if (choice == 'N' || choice == 'n')
{
choice = 'd';
continue;
}
else if (choice == 'Y' || choice == 'y')
{
obj.TypeAnswer(user);
obj.displayCurrent();
cout << endl;
}
else
{
cout << "Invalid input";
}
}
}
else if (choice == 'a')
{
obj.displayPrevious();
if (!obj.isAnswerGiven())
{
cout << GREEN << "Want to answer(Press: Y/N): " << RESET;
cin >> choice;
cin.ignore();
choice = tolower(choice);
if (choice == 'N' || choice == 'n')
{
choice = 'd';
continue;
}
else if (choice == 'Y' || choice == 'y')
{
obj.TypeAnswer(user);
obj.displayCurrent();
cout << endl;
}
else
{
cout << "Invalid input"; // ask again for invlaid input
}
}
}
cout << endl;
cout << GREEN << "Press D to go forward : Press A to fo backward (Press 0 to go back)" << RESET << endl;
cin >> choice;
}
}
// Recommend other people to the users`
void Recommend(string curr_user)
{
system("cls");
cout << LARGER << YELLOW << "Recommended User" << NORMAL << RESET << endl;
Recommendation obj;
vector<string> following;
vector<string> vertices;
string filename = "registrationdata/" + curr_user + ".txt";
following = obj.getFollowingInfo(filename); // profile
if (following.size() == 0)
{
noFollowingdisconnectedvertex();
return;
}
vector<vector<string>> ffUsers;
for (const auto &user : following)
{
string fileName = "registrationdata/" + user + ".txt"; // profile used
vector<string> temp = obj.getFollowingInfo(fileName);
temp.insert(temp.begin(), user);
ffUsers.push_back(temp);
}
for (const auto &user : ffUsers)
{
for (const auto &followingUser : user)
{
vertices.push_back(followingUser);
}
}
Graph graph(vertices);
for (const auto &user : ffUsers)
{
graph.addEdge(curr_user, user[0]);
string temp = user[0];
for (int i = 1; i < user.size(); i++)
{
graph.addEdge(temp, user[i]);
}
}
graph.displayDisconnectedVertices(curr_user);
}
void noFollowingdisconnectedvertex(void)
{
Recommendation obj;
vector<string> vertices;
string filename = "logindata.txt", str;
ifstream read;
read.open(filename);
while (!getline(read, str).eof())
{
vertices.push_back(str);
getline(read, str);
}
Graph reccommend_graph(vertices);
for (const auto &user : vertices)
{
string curr = user;
vector<string> temp = obj.getFollowingInfo(("registrationdata/" + user + ".txt"));
for (int i = 0; i < temp.size(); i++)
{
reccommend_graph.addEdge(curr, temp[i]);
}
}
reccommend_graph.displayVerticesWithInwardEdges();
}
// for updating loged in user profile
void update(Profile &N, string user)
{
system("cls");
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* \033[0m" << MAGENTA << "Update Profile" << RESET << "\033[1;36m *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m* ````````````````````` *\033[0m" << endl;
cout << "\t\t\t\t\033[1;36m******************************************************************************\033[0m" << endl;
cout << endl;
// cout << "\t\t\t\t\t1." << YELLOW << "User Name" << RESET << endl;
cout << "\t\t\t\t\t1." << YELLOW << "E-Mail" << RESET << endl;
cout << "\t\t\t\t\t2." << YELLOW << "About Yourself" << RESET << endl
<< endl;
cout << "\t\t\t\t\t" << RED << "Enter Your choice: " << RESET;
int choice;
string changing_string;
cin >> choice;
system("cls");
switch (choice)
{
cout << CYAN << "Enter the Details" << RESET << endl;
// case 1:
// cout << "Enter the User Name: " << endl;
// cout << BLUE << ": " << RESET;
// cin.ignore();
// getline(cin, changing_string);
// N.updateUser(changing_string, , user);
// break;
case 1:
cout << "Enter the Mail: ";
cin >> changing_string;
N.updateUser(changing_string, 2, user);
break;
case 2:
cout << "Enter about Yourself: " << endl;
cin.ignore();
getline(cin, changing_string);
N.updateUser(changing_string, 3, user);
break;
default:
return;
}
}
// show use profile
void showProfile(void)
{
ifstream read;
string str;
read.open("profile.txt");
getline(read, str);
cout << "ID: " << str << endl;
getline(read, str);
cout << "Name: " << str << endl;
getline(read, str);
cout << "User Name: " << str << endl;
getline(read, str);
cout << "DOB: " << str << endl;
getline(read, str);
cout << "Decription : " << str << endl;
getline(read, str);
cout << "Mail: " << str << endl;
getline(read, str);
cout << "Profession: " << str << endl;
}