Repository navigation
Expand file tree
/
Copy pathfunctions.cpp
More file actions
556 lines (533 loc) · 11.5 KB
/
Copy pathfunctions.cpp
File metadata and controls
556 lines (533 loc) · 11.5 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
#include "functions.h"
#include "memberException.h"
#include "dateException.h"
#include <string.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#define ADD_NEW_MEMBER 1
#define ADD_NEW_FAN_PAGE 2
#define ADD_NEW_STATUS_TO_MEMBER 3
#define ADD_NEW_STATUS_TO_FAN_PAGE 4
#define SHOW_ALL_STATUS_OF_MEMBER 5
#define SHOW_ALL_STATUS_OF_FAN_PAGE 6
#define SHOW_MEMBER_LATEST_FRIENDS_STATUSES 7
#define CREATE_NEW_FRIENDSHIP 8
#define CANCEL_FRIENDSHIP 9
#define ADD_FAN_TO_FAN_PAGE 10
#define REMOVE_FAN_TO_FAN_PAGE 11
#define SHOW_ALL 12
#define SHOW_ALL_MEMBER_FRIENDS 13
#define SHOW_ALL_FANS_OF_FAN_PAGE 14
#define EXIT 15
using namespace std;
// display the system menu.
void displayMenu()
{
cout << "1 - Add new member.\n2 - Add new fan page.\n3 - Add status to member.\n"
<<"4 - Add status to fan page.\n5 - Show a member statuses.\n6 - Show a fan page statuses\n"
<<"7 - Show a member latest 10 statuses.\n8 - Create new friendship between two members.\n"
<<"9 - Cancel a friendship between 2 friends\n10 - Add a members as a fan to a fan page.\n"
<<"11 - Remove a member from a fan page.\n12 - Show all members in facebook.\n"
<<"13 - Show a member friends.\n" "14 - Show a fan page fans.\n15 - Exit\n";
}
// get the user choice number, and based on it executing his choice.
bool getChoice(Facebook& facebook)
{
int choice;
displayMenu();
do {
cin >> choice;
} while (choice < 1 || choice > 15);
getchar();
switch (choice)
{
case ADD_NEW_MEMBER:
{
addNewMember(facebook);
break;
}
case ADD_NEW_FAN_PAGE:
{
addNewFanPage(facebook);
break;
}
case ADD_NEW_STATUS_TO_MEMBER:
{
if(facebook.getNumOfMembers() != 0)
addStatusToMember(facebook);
break;
}
case ADD_NEW_STATUS_TO_FAN_PAGE:
{
if (facebook.getNumOfMembers() != 0)
addStatusToPage(facebook);
break;
}
case SHOW_ALL_STATUS_OF_MEMBER:
{
showAllStatusOfMember(facebook);
break;
}
case SHOW_ALL_STATUS_OF_FAN_PAGE:
{
showAllStastusOfPage(facebook);
break;
}
case SHOW_MEMBER_LATEST_FRIENDS_STATUSES:
{
showLatestStatusOfFriend(facebook);
break;
}
case CREATE_NEW_FRIENDSHIP:
{
makeFriends(facebook);
break;
}
case CANCEL_FRIENDSHIP:
{
cancelFriendship(facebook);
break;
}
case ADD_FAN_TO_FAN_PAGE:
{
addMemberToPage(facebook);
break;
}
case REMOVE_FAN_TO_FAN_PAGE:
{
removeMemberFromPage(facebook);
break;
}
case SHOW_ALL:
{
showAll(facebook);
break;
}
case SHOW_ALL_MEMBER_FRIENDS:
{
showMemberFriends(facebook);
break;
}
case SHOW_ALL_FANS_OF_FAN_PAGE :
{
showPageFans(facebook);
break;
}
case EXIT:
{
cout << "------------------\nGOODBYE!\n------------------";
return false;
}
}
return true;
}
// adds a new member to facebook.
// gets from user the name and birthdate.
// if there is already a member in facebook with same name, free the name and the new member.
void addNewMember(Facebook& facebook)
{
int day, month, year;
string* name;
cout << "Please enter the new member's name:\n";
name = getString();
cout << "Please enter:\nDay Month Year, seperated with white space\n";
cin >> day >> month >> year;
Member* member = nullptr;
try
{
member = new Member(*name, Date(day, month, year));
facebook.addMember(*member);
}
catch (DuplicateNameException& dupName)
{
cout << dupName.what();
}
catch (InvalidBirthDate& invDate)
{
cout << invDate.what();
}
catch (InvalidDayException& dayExc)
{
cout << dayExc.what() << endl;
}
catch (InvalidMonthException& monthExc)
{
cout << monthExc.what() << endl;
}
catch (InvalidYearException& yearExe)
{
cout << yearExe.what() << endl;
}
catch (...)
{
cout << "something wrong. try again";
}
if(member)
delete member;
delete name;
}
// adds a new page to facebook.
// gets from user the name and birthdate.
// if there is already a page in facebook with same name, free the name and the new page.
void addNewFanPage(Facebook& facebook)
{
string* name;
cout << "Please enter the new page's name:\n";
name = getString();
FanPage* fanPage = new FanPage(*name);
try
{
facebook.addPage(*fanPage);
}
catch (DuplicateNameException& dupName)
{
cout << dupName.what();
}
catch (...)
{
cout << "something wrong. try again";
}
delete fanPage;
delete name;
}
// adds a new status to page.
// gets from user the page to add the status to, the date and the content.
void addStatusToPage(Facebook& facebook)
{
int choice;/* checkInputFanPages(facebook);*/
string* content = nullptr;
Status* newStatus = nullptr;
facebook.showPages(true);
cin >> choice;
getchar();
try
{
FanPage* fanPageChoice = facebook.findFanPage(choice - 1);
cout << "\nEnter content: \n";
content = getString();
newStatus = new Status(*content, Date(), Time());
facebook.addStatusToFanPage(*fanPageChoice, *newStatus);
}
catch(IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch(UserNotFound& unf)
{
cout << unf.what();
}
catch (...)
{
cout << "something wrong. try again";
}
if(newStatus)
delete newStatus;
if (content)
delete content;
}
// adds a new status to member.
// gets from user the member to add the status to, the date and the content.
void addStatusToMember(Facebook& facebook)
{
int choice;
string* content = nullptr;
Status* newStatus = nullptr;
facebook.showMembers(true);
cin >> choice;
getchar();
try
{
Member* memberChoice = facebook.findMember(choice - 1);
cout << "\nEnter content: \n";
content = getString();
newStatus = new Status(*content, Date(), Time());
facebook.addStatusToMember(*memberChoice, *newStatus);
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch (UserNotFound& unf)
{
cout << unf.what();
}
catch (...)
{
cout << "something wrong. try again";
}
if (newStatus)
delete newStatus;
if (content)
delete content;
}
// gets from user a string.
// returns a string
string* getString()
{
string* str = new string();
getline(cin, *str);
return str;
}
// gets from user a page choice and shows all of his statuses.
void showAllStastusOfPage(Facebook& facebook)
{
int choice;
facebook.showPages(true);
if (facebook.getNumOfPages() != 0)
{
cout << "Please choose one fan page:\n";
cin >> choice;
getchar();
try
{
facebook.findFanPage(choice - 1)->showAllStatus();
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch (...)
{
cout << "something wrong. try again";
}
}
}
// gets from user a member choice and shows all of his statuses.
void showAllStatusOfMember(Facebook& facebook)
{
int choice;
facebook.showMembers(true);
if (facebook.getNumOfMembers() != 0)
{
cout << "Please choose one member:\n";
cin >> choice;
getchar();
try
{
facebook.findMember(choice - 1)->showAllStatus();
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch (...)
{
cout << "something wrong. try again";
}
}
}
// gets from user a member choice and shows all of his friends 10 latest statuses.
void showLatestStatusOfFriend(Facebook& facebook)
{
int choice;
facebook.showMembers(true);
if (facebook.getNumOfMembers() != 0)
{
cout << "Please choose one member:\n";
cin >> choice;
getchar();
try
{
facebook.findMember(choice - 1)->showLatestFriendsStatus();
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch (...)
{
cout << "something wrong. try again";
}
}
}
// gets from user two members and connect both of them as friends on facebook
void makeFriends(Facebook& facebook)
{
int choice1, choice2;
int numOfMembers = facebook.getNumOfMembers();
facebook.showMembers(true);
if (numOfMembers != 0)
{
cout << "Please choose two members:\n";
cin >> choice1 >> choice2;
try
{
Member* temp1 = facebook.findMember(choice1 - 1);
Member* temp2 = facebook.findMember(choice2 - 1);
facebook.makeFriends(*temp1, *temp2);
}
catch (MemberToHimself& exp)
{
cout << exp.what() << endl;
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch (UserNotFound& unf)
{
cout << unf.what();
}
catch (...)
{
cout << "something wrong. try again";
}
}
}
// gets from user two members and remove them from being friends on facebook.
void cancelFriendship(Facebook& facebook)
{
int choice1;
int choice2;
int numOfMembers = facebook.getNumOfMembers();
facebook.showMembers(true);
if (numOfMembers != 0)
{
cout << "Please choose two members:";
try
{
cin >> choice1;
getchar();
cin >> choice2;
getchar();
Member* member1 = facebook.findMember(choice1 - 1);
Member* member2 = facebook.findMember(choice2 - 1);
facebook.cancelFriendship(*member2, *member1);
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
catch (MemberToHimself& sameMember)
{
cout << sameMember.removeMemberToHimself();
}
}
}
// gets from the user a member and a page choice.
// adds the member to be a fan of the fan page.
void addMemberToPage(Facebook& facebook)
{
int page;
int member;
int numOfMembers = facebook.getNumOfMembers();
int numOfPages = facebook.getNumOfPages();
facebook.showMembers(true);
if (numOfMembers != 0)
{
cout << "Please choose one member:";
cin >> member;
facebook.showPages(true);
if (numOfPages != 0)
{
cout << "Please choose one page:";
cin >> page;
try
{
FanPage* pageP = facebook.findFanPage(page - 1);
Member* memberP = facebook.findMember(member - 1);
facebook.addMemberToPage(*pageP, *memberP);
}
catch (UserNotFound& unf)
{
cout << unf.what();
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
}
}
}
// gets a member and a fan page and removes the member from being a fan of the page.
void removeMemberFromPage(Facebook& facebook)
{
int page;
int member;
int numOfMembers = facebook.getNumOfMembers();
int numOfPages = facebook.getNumOfPages();
facebook.showMembers(true);
if (numOfMembers != 0)
{
cout << "Please choose one member:";
cin >> member;
facebook.showPages(true);
if (numOfPages != 0)
{
cout << "Please choose one page:";
cin >> page;
try
{
FanPage* fanPageToRemoveFrom = facebook.findFanPage(page - 1);
Member* memberToRemove = facebook.findMember(member - 1);
facebook.removeMemberFromPage(*fanPageToRemoveFrom, *memberToRemove);
}
catch (UserNotFound& unf)
{
cout << unf.what();
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what();
}
}
}
}
// shows all members and pages on facebook.
void showAll(Facebook& facebook)
{
facebook.showMembers(false);
cout << "\n----------------\n";
facebook.showPages(false);
}
// gets a member and shows all of his friends
void showMemberFriends(Facebook& facebook)
{
int choice;
facebook.showMembers(true);
if (facebook.getNumOfMembers() != 0)
{
cout << "Please choose one member: ";
cin >> choice;
getchar();
try
{
Member* memberP = facebook.findMember(choice - 1);
facebook.showMemberFriend(*memberP);
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what()<<endl;
}
catch (UserNotFound& userNotFound)
{
cout << userNotFound.what() << endl;
}
}
}
// gets a page and shows all of his fans
void showPageFans(Facebook& facebook)
{
int choice;
facebook.showPages(true);
if (facebook.getNumOfPages() != 0)
{
cout << "Please choose one page: ";
cin >> choice;
getchar();
try
{
FanPage* fPage = facebook.findFanPage(choice - 1);
facebook.showPageFans(*fPage);
}
catch (IndexOutOfRange& indOutOfR)
{
cout << indOutOfR.what() << endl;
}
catch (UserNotFound& userNotFound)
{
cout << userNotFound.what() << endl;
}
}
}