-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMailBox.cpp
More file actions
979 lines (858 loc) · 22.1 KB
/
MailBox.cpp
File metadata and controls
979 lines (858 loc) · 22.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
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
#include<iostream>
#include<iomanip>
#include <ctime>
#include<vector>
#include <limits>
using namespace std;
//to deal with bad input
int input_num(string prompt)
{
int ch;
cout << prompt;
cin >> ch;
while (cin.fail())
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout << "\nInvalid input. Try again. \n" << prompt;
cin >> ch;
}
return ch;
}
//node for sent & received msg SLLs
class msg
{
public:
bool star; //true if msg is starred
bool sent; //true if msg has been sent to whom the user wishes to
bool read; //true if msg has been read by the logged-in user
string dt; //date & time when msg was sent/received
string to; //username of user to whom msg is sent
string from; //username of user from whom msg is sent
string text; //the actual message
msg *link;
msg()
{
star = false;
sent = false;
read = true;
to = "";
from = "";
text = "";
link = NULL;
}
};
//node for user DLL
class user
{
public:
bool logged_in;
string username;
string password;
msg *headS; //sent msg SLL head
msg *headR; //received msg SLL head
vector<msg*> trash; //vector of deleted msg
user *next;
user *prev;
friend class messager;
user()
{
logged_in = false;
username = "";
password = "";
headS = NULL;
headR = NULL;
next = NULL;
prev = NULL;
}
void display_msgs(string title, msg *head); //to display list of sent/inbox msg
void msg_options(string title, msg **head); //actions user can perform with displayed list of msg
void read_msg(msg *head); //to read a certain msg
void del_msg(msg **head); //to delete a certain msg
void starUnstar_msg(msg *m); //to mark an msg as important (star) or unstar
void vec_read_msg(vector<msg*> results); //to read msg from search results
void vec_del_msg(vector<msg*> results, msg **head); //to delete msg from search results
void vec_starUnstar(vector<msg*> results); //to star/unstar msg from search results
void search_msg(string title, msg **head); //to search msg sent to/ received from a user
void starred_msg(string title, msg **head); //displays list of starred msg
void trash_options(); //actions to perform on deleted msg
void del_permanently(); //to delete a msg from trash (permanently)
void read_trashMsg(); //to read a msg in trash
};
//to display list of sent/inbox msg
void user::display_msgs(string title, msg *head)
{
string R[] = { "unread", "read" };
string S[] = { "unstarred", "starred" };
cout <<"\n******************************* " <<title<< " *******************************";
if (head == NULL)
cout << "\nNo messages to display yet!\n";
else
{
int i = 1;
cout << "\n-------------------------------------------------------------------------------------------------";
cout << "\n" << setw(5) << "No." << setw(15) << "From" << setw(15)
<< "To" << setw(15) << "Message" << setw(14) << "When"
<< setw(10) << "Status" << setw(14) << "Starred";
cout << "\n-------------------------------------------------------------------------------------------------";
msg *m = head;
while (m != NULL)
{
cout << "\n" << setw(5) << i << setw(15) << m->from << setw(15)
<< m->to << setw(15) << m->text.substr(0, 8) << "..."
<< setw(14) << m->dt.substr(4, 6) << setw(10) << R[m->read]
<< setw(14) << S[m->star];
cout << "\n-------------------------------------------------------------------------------------------------";
m = m->link;
i++;
}
}
}
//actions user can perform with displayed list of msg
void user::msg_options(string title, msg **head)
{
int ch;
do
{
display_msgs(title, *head);
if (*head == NULL)
return;
cout << "\n********* " << title << " OPTIONS **********";
cout << "\n0. Exit";
cout << "\n1. Read a message";
cout << "\n2. Delete a message";
cout << "\n3. Star/Unstar a message";
ch = input_num("\nEnter your choice: ");
cout << "\n---------------------------------------------";
switch (ch)
{
case 0:
break;
case 1:
read_msg(*head);
break;
case 2:
del_msg(head);
break;
case 3:
starUnstar_msg(*head);
break;
}
} while (ch != 0);
}
//to read a certain msg
void user::read_msg(msg *head)
{
int no;
no = input_num("\nEnter message no. to read: ");
if (no < 1)
{
cout << "\nInvalid message no.";
return;
}
msg *ptr = head;
for (int i = 1; i < no; i++)
{
ptr = ptr->link;
if (ptr == NULL)
{
cout << "\nInvalid message no.";
return;
}
}
cout << "\n..................................................................";
cout << "\n************** MESSAGE " << no << " **************";
cout << "\nFrom : " << ptr->from;
cout << "\nTo : " << ptr->to;
cout << "\nWhen : " << ptr->dt;
cout << "\nMessage : \n" << ptr->text;
cout << "\n...................................................................\n";
ptr->read = true;
}
//to delete a certain msg //it adds the deleted msg to trash
void user::del_msg(msg **head)
{
if (*head == NULL)
{
cout << "No messages found.\n";
return;
}
int no = input_num("\nEnter message no. to delete: ");
if (no < 1)
{
cout << "\nInvalid message no.";
return;
}
msg *ptr = *head;
msg *prev = *head;
if (no == 1)
{
*head = (*head)->link;
cout << "Message deleted successfully!!\n";
trash.push_back(ptr);
return;
}
for (int i = 1; i < no; i++)
{
prev = ptr;
ptr = ptr->link;
if (ptr == NULL)
{
cout << "Invalid message no.\n";
return;
}
}
prev->link = ptr->link;
trash.push_back(ptr);
cout << "Message deleted successfully!!\n";
}
//to mark an msg as important (star) or unstar
void user::starUnstar_msg(msg *head)
{
int no = input_num("\nEnter message no. to star/unstar: ");
if (no < 1)
{
cout << "\nInvalid message no.";
return;
}
msg *ptr = head;
for (int i = 1; i < no; i++)
{
ptr = ptr->link;
if (ptr == NULL)
{
cout << "\nInvalid message no.";
return;
}
}
if (ptr->star == false)
{
ptr->star = true;
cout << "Message no. " << no << " has been starred.\n";
}
else
{
ptr->star = false;
cout << "Message no. " << no << " has been unstarred.\n";
}
}
//to read msg from search results or from starred msg list
void user::vec_read_msg(vector<msg*> results)
{
unsigned int no = unsigned(input_num("\nEnter message no. to read: "));
if (no < 1 || no > results.size())
{
cout << "\nInvalid message no.";
return;
}
msg *ptr = results.at(no - 1);
cout << "\n..................................................................";
cout << "\n************** MESSAGE " << no << " **************";
cout << "\nFrom : " << ptr->from;
cout << "\nTo : " << ptr->to;
cout << "\nWhen : " << ptr->dt;
cout << "\nMessage : \n" << ptr->text;
cout << "\n...................................................................\n";
ptr->read = true;
}
//to delete msg from search results or from starred msg list
void user::vec_del_msg(vector<msg*> results, msg **head)
{
unsigned int no = unsigned(input_num("\nEnter message no. to delete: "));
if (no < 1 || no > results.size())
{
cout << "\nInvalid message no.";
return;
}
msg *ptr = *head;
msg *prev = *head;
if (results.at(no - 1) == *head)
{
*head = (*head)->link;
cout << "\nMessage deleted successfully!";
trash.push_back(ptr);
results.erase(results.begin() + no - 1);
return;
}
for (ptr = *head; ptr != results.at(no - 1);)
{
prev = ptr;
ptr = ptr->link;
if (ptr == NULL)
{
cout << "Invalid message no.\n";
return;
}
}
prev->link = ptr->link;
ptr = results.at(no - 1);
trash.push_back(ptr);
results.erase(results.begin() + no - 1);
cout << "Message deleted successfully!!\n";
}
//to star/unstar msg from search results
void user::vec_starUnstar(vector<msg*> results)
{
unsigned int no = unsigned(input_num("\nEnter message no. to star/unstar: "));
if (no < 1 || no > results.size())
{
cout << "\nInvalid message no.";
return;
}
msg *ptr = results.at(no - 1);
if (ptr->star)
{
ptr->star = false;
cout << "Message no. " << no << " has been unstarred.\n";
}
else
{
ptr->star = true;
cout << "Message no. " << no << " has been starred.\n";
}
}
//to search msg sent to/ received from a user
void user::search_msg(string title, msg **head)
{
string un;
cout << "\nEnter the username: ";
cin >> un;
bool found = false;
msg *m = *head;
if (*head == NULL)
{
cout << "\nNo messages to display yet!";
return;
}
string cmp;
string R[] = { "unread", "read" };
string S[] = { "unstarred", "starred" };
int ch, i;
do
{
i = 0;
found = false;
vector<msg*> results;
for (m = *head; m != NULL; m = m->link)
{
if (title == "SENT TO ")
cmp = m->to;
else //"RECEIVED FROM "
cmp = m->from;
if (cmp == un)
{
if (!found)
{
cout<<"\n**************************** MESSAGES " <<title<< un << " ****************************";
cout<< "\n-------------------------------------------------------------------------------------------------";
cout<< "\n" << setw(5) << "No." << setw(15) << "From"
<< setw(15) << "To" << setw(15) << "Message"
<< setw(14) << "When" << setw(10) << "Status"
<< setw(14) << "Starred";
cout<< "\n-------------------------------------------------------------------------------------------------";
}
i++;
found = true;
results.push_back(m);
cout << "\n" << setw(5) << i << setw(15) << m->from << setw(15)
<< m->to << setw(15) << m->text.substr(0, 8) << "..."
<< setw(14) << m->dt.substr(4, 6) << setw(10)
<< R[m->read] << setw(14) << S[m->star];
cout << "\n-------------------------------------------------------------------------------------------------";
}
}
if (m == NULL && !found)
{
cout << "\nNo messages found!\n";
return;
}
cout << "\n********* MESSAGE OPTIONS **********";
cout << "\n0. Exit";
cout << "\n1. Read a message";
cout << "\n2. Delete a message";
cout << "\n3. Star/Unstar a message";
ch = input_num("\nEnter your choice: ");
cout << "\n---------------------------------------------";
switch (ch)
{
case 0:
break;
case 1:
vec_read_msg(results);
break;
case 2:
vec_del_msg(results, head);
break;
case 3:
vec_starUnstar(results);
break;
}
} while (ch != 0);
}
//displays list of starred msg
void user::starred_msg(string title, msg **head)
{
string R[] = { "unread", "read" };
string S[] = { "unstarred", "starred" };
msg *m = *head;
if (head == NULL)
{
cout << "\nNo messages to display yet!";
return;
}
int ch, i;
bool found;
vector<msg*> results;
do
{
i = 0;
found = false;
vector<msg*> results;
for (m = *head; m != NULL; m = m->link)
{
if (m->star == true)
{
if (!found)
{
cout << "\n**************************** STARRED MESSAGES IN "<< title << " ****************************";
cout << "\n-------------------------------------------------------------------------------------------------";
cout << "\n" << setw(5) << "No." << setw(15) << "From"
<< setw(15) << "To" << setw(15) << "Message"
<< setw(14) << "When" << setw(10) << "Status"
<< setw(14) << "Starred";
cout << "\n-------------------------------------------------------------------------------------------------";
}
i++;
found = true;
results.push_back(m);
cout << "\n" << setw(5) << i << setw(15) << m->from << setw(15)
<< m->to << setw(15) << m->text.substr(0, 8) << "..."
<< setw(14) << m->dt.substr(4, 6) << setw(10)
<< R[m->read] << setw(14) << S[m->star];
cout << "\n-------------------------------------------------------------------------------------------------";
}
}
if (m == NULL && !found)
{
cout << "\nNo messages found!\n";
return;
}
cout << "\n********* MESSAGE OPTIONS **********";
cout << "\n0. Exit";
cout << "\n1. Read a message";
cout << "\n2. Delete a message";
cout << "\n3. Star/Unstar a message";
ch = input_num("\nEnter your choice: ");
cout << "\n---------------------------------------------";
switch (ch)
{
case 0:
break;
case 1:
vec_read_msg(results);
break;
case 2:
vec_del_msg(results, head);
break;
case 3:
vec_starUnstar(results);
break;
}
} while (ch != 0);
}
//actions to perform on deleted msg
void user::trash_options()
{
int ch;
do
{
string R[] = { "unread", "read" };
string S[] = { "unstarred", "starred" };
if (this->trash.size() == 0)
{
cout << "Trash empty\n";
return;
}
cout<< "\n******************************* TRASH *******************************";
cout<< "\n-------------------------------------------------------------------------------------------------";
cout << "\n" << setw(5) << "No." << setw(15) << "From" << setw(15) << "To"
<< setw(15) << "Message" << setw(14) << "When" << setw(10)
<< "Status" << setw(14) << "Starred";
cout<< "\n-------------------------------------------------------------------------------------------------";
for (unsigned int i = 0; i < this->trash.size(); i++)
{
msg *m = this->trash[i];
cout << "\n" << setw(5) << i+1 << setw(15) << m->from << setw(15)
<< m->to << setw(15) << m->text.substr(0, 8) << "..."
<< setw(14) << m->dt.substr(4, 6) << setw(10) << R[m->read]<< setw(14) << S[m->star];
cout << "\n-------------------------------------------------------------------------------------------------";
}
cout << "\n********* TRASH OPTIONS **********";
cout << "\n0. Exit";
cout << "\n1. Delete a message permanently";
cout << "\n2. View a message";
ch = input_num("\nEnter your choice: ");
cout << "\n---------------------------------------------";
switch (ch)
{
case 0:
break;
case 1:
del_permanently();
break;
case 2:
read_trashMsg();
break;
}
} while (ch != 0);
}
//to delete a msg from trash (permanently)
void user::del_permanently()
{
unsigned int no = unsigned(input_num("\nEnter message no. to delete: "));
if (no > trash.size() || no < 1)
{
cout << "Invalid message no.\n";
return;
}
msg *m = trash[no - 1];
trash.erase(trash.begin() + no - 1);
cout << "Message permanently deleted\n";
delete m;
}
//to read a msg in trash
void user::read_trashMsg()
{
unsigned int no = unsigned(input_num("\nEnter message no. to read: "));
if (no < 1 || no > trash.size())
{
cout << "\nInvalid message no.";
return;
}
cout << "\n..................................................................";
cout << "\n************** MESSAGE " << no << " **************";
cout << "\nFrom : " << trash[no - 1]->from;
cout << "\nTo : " << trash[no - 1]->to;
cout << "\nWhen : " << trash[no - 1]->dt;
cout << "\nMessage : \n" << trash[no - 1]->text;
cout << "\n...................................................................\n";
trash[no - 1]->read = true;
}
class messager
{
user *start; //start pointer of user DLL
user *last; //pointer to last node of user DLL
public:
messager()
{
start = NULL;
last = NULL;
}
bool is_empty(); //returns true if no user has created account yet
user* accept(); //takes input required while creating a new account
void create(); //creates new user account & adds it to user DLL(sign-up)
void login(); //to login to an existing account
void remove(); //to delete your account
void change_pw(); //to change current password
void activity(user *ptr); //actions that user can perform while logged in
msg* msg_sent(); //takes input to send msg, updates receiver's inbox & returns pointer to sent msg
void send_msg(user *ptr); //calls msg_sent() & updates user's sent msg sll
};
//returns true if no user has created account yet
bool messager::is_empty()
{
if (start == NULL)
return true;
else
return false;
}
//takes input required while creating a new account
user* messager::accept()
{
bool un_exist = false;
user *tmp = new user();
user *ptr;
do
{
ptr = start;
cout << "\nEnter username to create : ";
cin >> tmp->username;
while (ptr != NULL)
{
if (ptr->username == tmp->username)
{
cout << "\nEntered username already exists.";
un_exist = true;
break;
}
ptr = ptr->next;
}
if (ptr == NULL)
un_exist = false;
} while (un_exist);
cout << "\nCreate password: ";
cin >> tmp->password;
return tmp;
}
//creates new user account & adds it to user dll(sign-up)
void messager::create()
{
user *tmp = accept();
if (is_empty())
{
start = tmp;
last = tmp;
}
else
{
last->next = tmp;
tmp->prev = last;
last = tmp;
}
cout << "\nYour account has been created successfully!";
}
//to login to an existing account
void messager::login()
{
string un, pw;
cout << "\nEnter username: ";
cin >> un;
for (user *ptr = start; ptr != NULL; ptr = ptr->next)
{
if (ptr->username == un)
{
cout << "\nEnter password: ";
cin >> pw;
if (ptr->password == pw)
{
ptr->logged_in = true;
cout << "\nSuccessfully logged in.";
activity(ptr);
return;
}
else
{
cout << "\nIncorrect password. Try again.";
return;
}
}
}
cout << "\nUsername not found.";
}
//to delete your account //removes ptr from user dll
void messager::remove()
{
char ch;
string un, pw;
cout << "\nEnter username: ";
cin >> un;
if (is_empty())
cout << "\nCurrently no user accounts exist.";
for (user *curr = start; curr != NULL; curr = curr->next)
{
if (curr->username == un)
{
cout << "\nEnter the password: ";
cin >> pw;
if (curr->password == pw)
{
do
{
cout << "Are you sure you want to delete your account?(Y/N): ";
cin >> ch;
if (ch == 'N') return;
else if (ch == 'Y') break;
else cout << "\nInvalid choice. Try again.";
} while (ch != 'Y' || ch != 'N');
//if start node
if (curr == start)
start = curr->next;
//if curr is not last node
if (curr->next != NULL)
(curr->next)->prev = curr->prev;
//if curr is not 1st node
if (curr->prev != NULL)
(curr->prev)->next = curr->next;
delete curr;
cout << "\nYour account has been deleted successfully!";
return;
}
else
{
cout << "\nIncorrect password....please try again.";
return;
}
}
}
cout << "\nUsername not found.";
}
//to change current password
void messager::change_pw()
{
string un, pw, pw1;
cout << "\nEnter username: ";
cin >> un;
for (user *ptr = start; ptr != NULL; ptr = ptr->next)
{
if (ptr->username == un)
{
do
{
cout << "\nEnter previous password: ";
cin >> pw;
if (ptr->password == pw)
{
cout << "\nEnter new password : ";
cin >> pw1;
ptr->password = pw1;
cout << "\nYour password has been changed successfully!";
return;
}
else
cout << "\nIncorrect previous password.\n";
} while (true);
}
}
cout << "\nUsername not found.";
}
//actions that user can perform while logged in
void messager::activity(user *ptr)
{
int ch;
do
{
cout << "\n************* HELLO @"<< ptr->username<< " ! *************";
cout << "\n0. Logout";
cout << "\n1. Check inbox messages";
cout << "\n2. Send a message";
cout << "\n3. View sent messages";
cout << "\n4. Search messages sent to an user";
cout << "\n5. Search messages received from an user";
cout << "\n6. View deleted messages";
cout << "\n7. View starred messages in Inbox";
cout << "\n8. View starred messages in Sentbox";
ch = input_num("\nEnter your choice: ");
cout << "\n------------------------------------------\n";
switch (ch)
{
case 0:
ptr->logged_in = false;
cout << "\nSuccessfully logged out.";
return;
case 1:
ptr->msg_options("INBOX", &ptr->headR);
break;
case 2:
send_msg(ptr);
break;
case 3:
ptr->msg_options("SENT", &ptr->headS);
break;
case 4:
ptr->search_msg("SENT TO ", &ptr->headS);
break;
case 5:
ptr->search_msg("RECEIVED FROM ", &ptr->headR);
break;
case 6:
ptr->trash_options();
break;
case 7:
ptr->starred_msg("INBOX ", &ptr->headR);
break;
case 8:
ptr->starred_msg("SENTBOX ", &ptr->headS);
break;
default:
cout << "\nInvalid choice";
}
} while (ch != 0);
}
//takes input to send msg, updates receiver's inbox & returns pointer to sent msg
msg* messager::msg_sent()
{
msg *m = new msg();
user *ptrT; //pointer To whom user is sending msg
bool un_exist = false;
do
{
cout << "Enter username of user to message : ";
cin >> m->to;
getchar(); //'\n'
//updating receiver's received msg sll
for (ptrT = start; ptrT != NULL; ptrT = ptrT->next)
{
if (ptrT->username == m->to)
{
cout << "\nEnter message you want to send to @" <<m->to<< " :\n";
getline(cin, m->text);
m->read = false;
time_t now = time(0); // current date/time based on current system
m->dt = ctime(&now); // convert now to string form
un_exist = true;
cout << "\nMessage sent successfully to @" << m->to;
//insert new msg at beginning of ptrT's received msg sll
m->link = ptrT->headR;
ptrT->headR = m;
return m;
}
}
if (ptrT == NULL) //!un_exist
cout << "\nEntered username doesn't exist.\n";
} while (un_exist == false);
return m;
}
//calls msg_sent() & updates user's sent msg sll
void messager::send_msg(user *ptr)
{
msg *ms = msg_sent(); //pointer to sent msg
ms->from = ptr->username;
//updating sender's (logged-in user's) sent msg sll
msg *m = new msg(); //create new msg to update user's sent msgs sll
m->sent = true;
m->to = ms->to;
m->from = ms->from;
m->dt = ms->dt;
m->text = ms->text;
//insert sent msg at beginning of sent sll
m->link = ptr->headS;
ptr->headS = m;
}
int main()
{
int ch;
messager A;
do
{
cout << "\n----------------------------------------";
cout << "\n******** WELCOME TO MESSAGER **********";
cout << "\n0. Exit application";
cout << "\n1. Create new account";
cout << "\n2. Login to your account";
cout << "\n3. Delete an existing account";
cout << "\n4. Change Password";
ch = input_num("\nEnter your choice: ");
cout << "\n----------------------------------------";
switch (ch)
{
case 0:
cout << "\n********* PROGRAM ENDED **********";
break;
case 1:
A.create();
break;
case 2:
A.login();
break;
case 3:
A.remove();
break;
case 4:
A.change_pw();
break;
default:
cout << "\nInvalid choice";
}
} while (ch != 0);
return 0;
}