-
Notifications
You must be signed in to change notification settings - Fork 0
/
thesocialnetwork.cpp
595 lines (519 loc) · 21.9 KB
/
thesocialnetwork.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
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
struct User_input{
string firstname, surname, email, password;
int choice1, choice2; // CHOICE1 = OUTER , CHOICE2 = INNER
bool toLoop = true;
};
class User{
private:
string user_password;
string email_address;
public:
string first_name;
string sur_name;
string filename;
string gender;
string birthday;
string post;
string setPassword(string password){
this->user_password = password;
}string getPassword(){
return user_password;
}
string setEmail(string email){ //for email
this->email_address = email;
}string getEmail(){
return email_address;
}
void HomePage(ifstream &User_file, string firstname, string surname, string gender, string birthday, string for_email, string for_password, ofstream &User_fileO);
//void Profile(ifstream &User_file, string firstname, string for_email, string for_password);
};
void OFile(ofstream &User_fileO, string first_name, string surname, string gender, string birthday, string email, string password, string post){
User_fileO << first_name << " " << surname << " " << gender << " " << birthday << " " <<email << " " << password << " " << post << " ";
}
void Convert(string name){ //Convert to Lowercase
int length = name.length();
for (int i=0; i<length; i++){
if(name[i] >= 'A' && name[i]<= 'Z'){
name = name[i] +32;
}
else{
name = name[i];
}
}
}
void Convert_Upper(string& input){ //Convert to uppercase
for (int i=0; i < input.length(); i++){
input[i] = toupper(input[i]);
}
}
void MindTwist(){
bool toEnd = false;
string input, choice;
while (toEnd == false){
cout << "\t\t Welcome to Mind Twist! " << endl << endl << "\t\t";
cout << "Enter a word, phrase or a sentence: " << endl << endl << "\t\t";
getline(cin,input);
cout << endl << endl; Sleep(500);
Convert_Upper(input);
for(int i=0;input[i]!='\0';i++){
switch (input[i]){
case 'A':input[i]='4';
break;
case 'E':input[i]='3';
break;
case 'I':input[i]='1';
break;
case 'O':input[i]='0';
break;
case 'S':input[i]='5';
break;
case 'T':input[i]='7';
}
}
cout<<": " << input << endl << endl;
cout << "Do you want to convert again? [ Y | N ]: ";
cin >> choice;
cin.ignore();
if (choice == "y" || choice == "Y"){
cout << "Loading ."; Sleep(500); cout <<"."; Sleep(500); cout <<"."; Sleep(2000);
system("cls");
}else if (choice == "n" || choice == "N"){
cout << "Redirecting to Games ."; Sleep(500); cout <<"."; Sleep(500); cout <<"."; Sleep(2000);
system("cls");
toEnd = true;
}else{
cout <<"Invalid Choice, Redirecting to Games ."; Sleep(500); cout <<"."; Sleep(500); cout <<"."; Sleep(2000);
system("cls");
toEnd = true;
}
}
}
void RPS(){
int computer;
char user, playAgain;
enum GameStates{
ROCK, PAPER, SCISSORS
};
bool Quit = false;
//cout << "\tRock, Paper and Scissors! " << endl <<endl <<endl; Sleep(900);
// while loop until Quit falls to true
while(1){
if (Quit)
break;
{
cout << "\tRock, Paper and Scissors! " << endl <<endl <<endl;
cout << " Choose your weapon:" << endl; Sleep(400);
cout << " R for Rock" << endl; Sleep(400);
cout << " P for Paper" << endl; Sleep(400);
cout << " S for Scissors" << endl; Sleep(400);
cout << " Q for Quit" << endl << endl; Sleep(400);
cout << endl << " : ";
cin >> user;
user = tolower(user);
if (user == 'q'){
Quit = true;
cout << " Thanks for Playing." << endl;
break;
}
while (1){
if (!(user == 'r' || user == 'p' || user == 's'))
{ cout << " Invalid Option! Please try again." << endl << endl;
cout << ": ";
cin >> user;
if (user == 'q'){
exit(1);
break;
}
}else{
break;
}
}
cout <<endl <<endl;
// Computer's moves
computer = rand() % 3; /*generate pseudo-random numbers in a determined range of 0-3 */
switch(computer){
case ROCK:
if (user == 'r')
cout << "Computer chose 'ROCK'... Tied!" << endl;
if (user == 'p')
cout << "Computer chose 'ROCK'... You Win!" << endl;
if (user == 's')
cout << "Computer chose 'ROCK'... You Lose!" << endl;
break;
case PAPER:
if (user == 'r')
cout << "Computer chose 'PAPER'... You Lose!" << endl;
if (user == 'p')
cout << "Computer chose 'PAPER'... Tied!" << endl;
if (user == 's')
cout << "Computer chose 'PAPER'... You Win!" << endl;
break;
case SCISSORS:
if (user == 'r')
cout << "Computer chose 'SCISSORS'... You Win!" << endl;
if (user == 'p')
cout << "Computer chose 'SCISSORS'... You Lose!" << endl;
if (user == 's')
cout << "Computer chose 'SCISSORS'... Tied!" << endl;
break;
default:
cout << "Please try again." << endl;
system("cls");
break;
}
// Play again?
cout << endl << "Play again [Y/N]?: " ;
cin >> playAgain;
playAgain = tolower(playAgain);
switch(playAgain){
case 'y':
system("CLS");
break;
case 'n':
Quit = true;
cout << endl << endl << "Thanks for Playing!" << endl;
break;
default:
cout << endl << endl << "Invalid choice! Redirecting back to game."; cout << "."; cout << "."; Sleep(700);
system("CLS");
break;
}
}
}
}
void News(){
int newsChoice;
char ch;
bool toEnd = false;
FILE * fPtr;
while(toEnd == false){
cout<<"\t NEWS"<<endl<<endl;
cout<<"What do you want to read?"<<endl;
cout<<"[1] COVID-19"<<endl;
cout<<"[2] Technology"<<endl;
cout<<"[3] Science"<<endl;
cout<<"[4] Entertainment"<<endl;
cout<<"[5] Back "<< endl <<endl<<endl;
cout<<": ";
cin>>newsChoice;
if (newsChoice == 1) { // COVID-19
fPtr = fopen("news/COVID19.txt", "r");
if(fPtr == NULL){
cout<<"Unable to open file.\n";
cout<<"Please check whether file exists and you have read privilege.\n";
exit(EXIT_FAILURE);
}
cout<<"\nNews opened successfully. Fetching top COVID-19 news from Google News... \n\n";
do {
ch = fgetc(fPtr);
putchar(ch);
} while(ch != EOF);
fclose(fPtr);
system("pause");
system("cls");
}
else if (newsChoice == 2) { // Technology
fPtr = fopen("news/Tech.txt", "r");
if(fPtr == NULL){
cout<<"Unable to open file.\n";
cout<<"Please check whether file exists.\n";
exit(EXIT_FAILURE);
}
cout<<"\nNews opened successfully. Fetching top Tech news from Google News... \n\n";
do {
ch = fgetc(fPtr);
putchar(ch);
} while(ch != EOF);
fclose(fPtr);
system("pause");
system("cls");
}
else if (newsChoice == 3) { // Science
fPtr = fopen("news/Science.txt", "r");
if(fPtr == NULL){
cout<<"Unable to open file.\n";
cout<<"Please check whether file exists.\n";
exit(EXIT_FAILURE);
}
cout<<"\nNews opened successfully. Fetching top Science news from Google News... \n\n";
do {
ch = fgetc(fPtr);
putchar(ch);
} while(ch != EOF);
fclose(fPtr);
system("pause");
system("cls");
}
else if (newsChoice == 4) { // Entertainment
fPtr = fopen("news/Entertainment.txt", "r");
if(fPtr == NULL){
cout<<"Unable to open file.\n";
cout<<"Please check whether file exists.\n";
exit(EXIT_FAILURE);
}
cout<<"\nNews opened successfully. Fetching top Entertainment news from Google News... \n\n";
do {
ch = fgetc(fPtr);
putchar(ch);
} while(ch != EOF);
fclose(fPtr);
system("pause");
system("cls");
}
else if (newsChoice == 5) {
cout << "Redirecting to Homepage ."; Sleep(500); cout <<"."; Sleep(500); cout <<"."; Sleep(700);
system("cls");
toEnd = true;
}else{
system("cls");
}
}
}
void User::HomePage(ifstream &User_file, string firstname, string surname, string gender, string birthday, string for_email, string for_password, ofstream &User_fileO){ // HOMEPAGE
User user;
User_input input;
string full_name;
HOMEPAGE:
while (input.toLoop == true){
User_file.open(user.filename.c_str());
if(!User_file.is_open()){
cout << "File doesn't exist!"<<endl;
}
else{
cout << "File is ready" << endl;
cout << "Welcome ";
User_file >> firstname >> surname >> gender >> birthday >> for_email >> for_password;
cout << firstname << "!" << endl << endl;
cout << "[1]Profile \t\t [2]Post \t\t [3]Games \t\t [4]News \t\t [5]Logout \t\t" << endl << endl;
cout << "What do you want to do?: ";
cin >> input.choice1;
switch (input.choice1){
case 1: // PROFILE
system("cls");
PROFILE:
cout << firstname << "'s PROFILE " << endl << endl;
cout << "[1]View \t\t [2]Exit Profile" << endl << endl;
cout << "What do you want to do?: ";
cin >> input.choice2;
//user.Profile(User_file, user.first_name, user.getEmail(), user.getPassword());
if(input.choice2 == 1){ // VIEW PROFILE
system("cls");
cout << "View Profile" << endl << endl;
User_file >> firstname >> surname >> gender >> birthday >> for_email >> for_password;
full_name = firstname + " " + surname;
cout << "\t Name: ";
cout << full_name <<endl;
cout << "\t Gender: ";
cout << gender << endl;
cout << "\t Birthday: ";
cout << birthday << endl;
cout << "[1]Back" << endl<<endl;
cout << "What do you want to do?: "; // GO BACK TO PROFILE PAGE
cin >> input.choice2;
if(input.choice2 == 1){
system("cls");
goto PROFILE;
}else{
cout << "Invalid choice!";
}
}else if (input.choice2 == 2){ // EDIT PROFILE
cout << "Exit";
system("cls");
}
break;
case 2:
system("cls");
POST:
cout << "POST" << endl;
cout <<"[1]Write Post \t\t [2]View Post \t\t [3]Back" << endl << endl;
cout << ": ";
cin >> input.choice1;
if(input.choice1 == 1){ // WRITE POST
cin.ignore();
cout << "\t\tTell The World How Your Feeling: "<<endl << endl << "\t\t" ;
getline(cin, user.post);
ofstream User_fileO;
User_fileO.open(user.filename.c_str());
OFile(User_fileO, user.first_name, user.sur_name, user.gender, user.birthday, input.email, input.password, user.post);
User_fileO.close();
cout << endl <<endl<<endl;
system("pause");
system("cls");
goto POST;
}else if (input.choice1 == 2){ // EDIT POST
system("cls");
cout << "\t\tView your Posts: "<< endl << endl << "\t\t";
User_file.open(user.filename.c_str());
User_file >> user.post;
cout << user.post << endl <<endl <<endl;
system("pause");
system("cls");
goto POST;
}else if(input.choice1 == 3){
system("cls");
}
break;
case 3:
system("cls");
GAMES:
cout << "GAMES" << endl;
cout << "[1]Mind Twist \t\t [2]Rock Paper Scissors \t\t [3]Back" << endl <<endl;
cout << "\t: ";
cin >> input.choice1;
cin.ignore();
if(input.choice1 == 1){
system("cls");
MindTwist();
system("cls");
goto GAMES;
}else if (input.choice1 == 2){
system("cls");
RPS();
system("cls");
goto GAMES;
}else if (input.choice1 == 3){
system("cls");
}else{
cout << "Invalid choice, Redirecting to Games ."; Sleep(500); cout <<"."; Sleep(500); cout <<"."; Sleep(700);
goto GAMES;
}
break;
case 4:
system("cls");
News();
system("cls");
break;
case 5:
system("cls");
User_file.close();
cout << "Thank You For Using The Program! " << endl;
exit(0);
break;
default:
cout << "Invalid choice!" << endl;
break;
}
}
}
}
int main()
{
User user;
User_input input;
string name, for_email, for_password;
ofstream User_fileO;
ifstream User_file;
while (input.toLoop == true){ // PORTAL
cout<<"[1] Login" << endl;
cout<<"[2] Sign up" <<endl;
cout<<"[3] Exit" << endl <<endl;
cout<<"Select an Option: ";
cin >> input.choice1;
cout << endl << endl;
if(input.choice1 == 1){ // LOGIN
while (input.toLoop == true){
//system("cls");
cout << "Enter below your first name to access the file where your info are saved. Please don't include spaces."<<endl;
cout << "First Name: ";
cin >> name;
user.filename = name + ".txt";
User_file.open(user.filename.c_str());
if (!User_file.is_open()){ // IF FILE DOES NOT EXIST
cout <<"FILE NOT FOUND" << endl << endl; system("pause");
cout << endl << "Invalid File name! "; Sleep(400);
cout << "File doesn't exist."; Sleep(1000);
system("cls");
}
else
{
cin.ignore();
system("cls");
cout <<"FILE IS READY" << endl << endl; // IF FILE EXIST
LOGIN:
cout <<endl << endl<< "Email: ";
getline(cin, input.email);
cout <<endl<< "Password: ";
getline(cin, input.password);
Convert(name);
for_email = user.getEmail();
for_password = user.getPassword();
// FILE ACCESS (ACCESS DATA FROM FILE)
User_file >> user.first_name >> user.sur_name >> user.gender >> user.birthday >> for_email >> for_password;
while(input.toLoop == true){
if(input.email == for_email && input.password == for_password){
system("cls");
cout<<" Logging in . "; Sleep(400);
cout << ". "; Sleep(400);
cout << ". " <<endl;
system("cls");
input.toLoop = false;
user.HomePage(User_file, user.first_name, user.sur_name, user.gender, user.birthday, user.getEmail(), user.getPassword(), User_fileO); //ACCESS HOMEPAGE FUNCTION
}
else{
cout<<"Email or Password is invalid!"<<endl; Sleep(400);
cout<<"Try again, Redirecting to Login . "; Sleep(400);
cout<<". "; Sleep(400);
cout<<". " << endl;
system("cls");
goto LOGIN;
}
}
}
}
}else if (input.choice1 == 2){ //SIGN UP
cout << "First Name: ";
cin >> input.firstname;
cout << endl;
cout << "Last Name: ";
cin >> input.surname;
GENDER:
cout << "Gender (Male[M] | Female[F]): "; // TO CONVERT M -> MALE / F -> FEMALE
cin >> user.gender;
if(user.gender == "M" || user.gender == "m"){
user.gender = "Male";
}else if(user.gender == "F" || user.gender == "f"){
user.gender = "Female";
}else{
goto GENDER;
}
cin.ignore();
cout << "Birthday (use the format mm/dd/yy): ";
getline(cin, user.birthday);
cout << endl<< "Email: ";
getline(cin, input.email);
cout << "Password: ";
getline(cin, input.password);
//CONVERT to access class variables
user.first_name = input.firstname;
user.sur_name = input.surname;
user.setEmail(input.email);
user.setPassword(input.password);
Convert(input.firstname);
user.filename = user.first_name + ".txt"; // TO MATCH FILE FORMAT
// FILE ACCESS (STORE DATA TO FILE)
User_fileO.open(user.filename.c_str());
OFile(User_fileO, user.first_name, user.sur_name, user.gender, user.birthday, input.email, input.password, user.post);
User_fileO.close();
system("cls");
cout<<"Creating Account. "; Sleep(400);
cout<<". "; Sleep(400);
cout<<". " << endl <<"Account Created! " <<endl;
system("cls");
}
else if (input.choice1 == 3){
cout << "Thankyou, for using the program!!" << endl;
exit(0);
}
else {
cout << "Invalid Choice, "; Sleep(500);
cout << "Please choose again." << endl;
system("cls");
}
}
}