-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoneBook.cpp
999 lines (993 loc) · 46.4 KB
/
PhoneBook.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
//This Code Belongs to Ahmed Hossam Khalil
#include <iostream> // The Main Library
#include <vector> //The Library That Called when i use the Vector
#include <iterator> // The Library That Called when i use the iterator
#include <fstream> // The Library That Called when i use the file stream
#include <iomanip> // The Library That Called when i Need to Handling The output
#include <windows.h> // The Library That Called in Function Call
#include <utility> // The Library That Called when i use Pair
using namespace std ;
class Duration{
public:
int minutes , seconds ;
public:
Duration(int minutes = 0, int seconds = 0 ){
this -> minutes = minutes ;
this -> seconds = seconds ;
}
};
class Contact { //Member Data
public:
int id ;
string name , phone ;
//Member Function
public:
Contact(int id = 0, string name = "", string phone = ""){ //Constructor
this -> id = id ;
this -> name = name ;
this -> phone = phone ;
}
void Show_contact(){ //Function Definition
cout << "*****************************************************************\n" ;
cout << "||ID||.........|| Name ||.........|| Phone.No ||\n" ;
cout << "*****************************************************************\n" ;
cout << " " << id << setw(23) << name << setw(21) << phone << "\n" ;
}
string lower_case(string word){
for(int i = 0 ; i < word.size() ; i++) {
(word[i] >= 65 && word[i] <= 90 ? word[i] += 32 : word[i] += 0);
}
return word ;
}
bool Find(string word){
word = lower_case(word) ;
return lower_case(name).find(word) != string::npos;
}
bool Find_phone(string word){
return lower_case(phone).find(word) != string::npos;
}
};
class Call_log{
public:
pair <Contact , Duration> call;
Call_log(Contact C1 , Duration Time){
call.first = C1 , call.second = Time ;
}
void Show_log(){
cout << " " << call.first.id << setw(23) << call.first.name << setw(21) << call.first.phone;
cout << setw(16) << (call.second.minutes < 10 ? "0" : "" ) << call.second.minutes ;
cout << ":" << (call.second.seconds < 10 ? "0" : "" ) << call.second.seconds << "\n";
}
};
class PhoneBook_System{ //Class Definition
//Member Data
vector <Contact> contacts ; vector <Call_log> log ;
public:
bool End = false ;
//Member Function
PhoneBook_System(){
input_Contacts() , input_Calls() ;
}
~PhoneBook_System(){
update_Contacts() , update_Calls() ;
}
void input_Contacts(){
ifstream input_Contacts("Contacts.txt") ;
int id ; string name , phone ;
while(input_Contacts >> id >> name >> phone) {
for(int i = 0 ; i < name.size() ; i++)
if(name[i] == '*') name[i] = ' ' ;
contacts.emplace_back(id ,name,phone) ;
}
}
void input_Calls() {
ifstream input_Calls("Calls.txt");
int id, minutes, seconds; string name, phone ; char c ;
while (input_Calls >> id >> name >> phone >> minutes >> c >> seconds) {
for(int i = 0 ; i < name.size() ; i++)
if(name[i] == '*') name[i] = ' ' ;
log.emplace_back(Contact(id, name, phone), Duration(minutes, seconds));
}
}
void update_Contacts(){
ofstream output_Contacts("Contacts.txt") ;
for(int i = 0 ; i < contacts.size() ; i++){
for(int j = 0 ; j < contacts[i].name.size() ; j++)
if (contacts[i].name[j] == ' ') contacts[i].name[j] = '*' ;
output_Contacts << " " << contacts[i].id << setw(23) << contacts[i].name << setw(21) << contacts[i].phone << "\n" ;
}
}
void update_Calls(){
ofstream output_Calls("Calls.txt") ;
for(int i = 0 ; i < log.size() ; i++){
for(int j = 0 ; j < log[i].call.first.name.size() ; j++)
if (log[i].call.first.name[j] == ' ') log[i].call.first.name[j] = '*' ;
output_Calls << " " << log[i].call.first.id << setw(23) << log[i].call.first.name << setw(21) << log[i].call.first.phone;
output_Calls << setw(12) << log[i].call.second.minutes ;
output_Calls << ':' << log[i].call.second.seconds << "\n";
}
}
void Swap_Contacts(){
for(int i = 0 ; i < contacts.size() ; i++)
for(int j = 0 ; j < contacts.size() ; j++)
if(lower(contacts[i].name) < lower(contacts[j].name) && i != j)
swap(contacts[i] , contacts[j]) ;
}
string lower(string name){
for(int i = 0 ; i < name.size() ; i++){
if(name[i] >= 'A' && name[i] <= 'Z'){
name[i] += 32 ;
}
}
return name ;
}
void New_Contact(){ //Function to Add New Contact
system("cls");
cout << "*****************************************************************\n" ;
int id, i = 0 ; bool Add = false , Same = false ; string name ,phone ;
cout << "Enter your New Contact's Name: " ; getline(cin,name) ,getline(cin,name);
cout << "Enter your New Contact's Phone: " ; cin >> phone ;
id = contacts.size() + 1 ;
for(int k = 0 ; k < name.size() ; k++) {
if (name[0] >= 97 && name[0] <= 122) {
name[0] -= 32;
continue;
}
if (name[k] == ' ') {
if (name[k + 1] >= 97 && name[k + 1] <= 122) name[k + 1] -= 32;
}
}
Contact C1(id,name,phone) ;
for(int j = 0 ; j < contacts.size() ;j++){
if(lower(contacts[j].phone) == lower(phone)){
Same = true ;
break ;
}
}
if(Same){
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... There is a Contact Matched with this Number\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_a ; cin >> Choice_a ;
if(Choice_a == 1) New_Contact() ;
else if (Choice_a == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
for(auto it = contacts.begin() ; it != contacts.end() ; it++ , i++) {
if (it -> name > name or i == contacts.size()) {
auto it = contacts.insert(contacts.begin() + i , C1);
Add = true ; break;
}
}
if (!Add) contacts.push_back(C1) ;
for(int j = 0 ; j < contacts.size() ; j++){
contacts[j].id = j + 1 ;
}
for(int j = 0 ; j < log.size() ;j++){
if(log[j].call.first.phone == phone){
log[i].call.first.name = name ;
break ;
}
}
cout << "*****************************************************************\n" ;
cout << "New Contact Added\n";
Again_add :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Add another Contact (Yes or No): " ;
string yes_no_Add ;
cin >> yes_no_Add ;
if(lower(yes_no_Add) == "yes"){
New_Contact() ;
}else if(lower(yes_no_Add) == "no"){
Interface() ;
}else {
cout << "Not Valid! .. Try Again\n" ;
goto Again_add ;
}
}
void Search_ByName(){ //Function to Search For Contact By Using Name
system("cls");
cout << "*****************************************************************\n" ;
bool is_Found = false , Duplicated = false ; string name ;
cout << "Enter Your Contact's Name that you want to Search: " ;
getline(cin,name),getline(cin,name) ;
for(int it = 0 ; it < contacts.size() ; it++){
if (lower(contacts[it].name) == lower(name) || contacts[it].Find(name)){
is_Found = true ;
if(!Duplicated) {
contacts[it].Show_contact() ;
Duplicated = true ;
}else
cout << " " << contacts[it].id << setw(23) << contacts[it].name << setw(21) << contacts[it].phone << "\n" ;
}
}
if(!is_Found) {
cout << "*****************************************************************\n" ;
cout << "No Contact Found with this Name\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_sn ; cin >> Choice_sn ;
if(Choice_sn == 1) Search_ByName() ;
else if (Choice_sn == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
Again_SN :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Search for another Contact (Yes or No): " ;
string yes_no_SN ;
cin >> yes_no_SN ;
if(lower(yes_no_SN) == "yes"){
Search_ByName() ;
}else if(lower(yes_no_SN) == "no"){
Interface() ;
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_SN ;
}
}
void Search_ByID(){ //Function to Search For Contact By Using ID
system("cls");
cout << "*****************************************************************\n" ;
int id ;
cout << "Enter your Contact's ID that you want to Search: " ;
cin >> id ;
if (id - 1 >= contacts.size() || id - 1 < 0 ) {
cout << "*****************************************************************\nNo Contact Found with this ID\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_id ; cin >> Choice_id;
if(Choice_id == 1) Search_ByID() ;
else if (Choice_id == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}else {
contacts[id - 1].Show_contact() ;
}
Again_SID :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Search for another Contact (Yes or No): " ;
string yes_no_SID ;
cin >> yes_no_SID ;
if(lower(yes_no_SID) == "yes"){
Search_ByID() ;
}else if(lower(yes_no_SID) == "no"){
Interface() ;
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_SID ;
}
}
void Search_ByPhone(){ //Function to Search For Contact By Using Phone
system("cls");
cout << "*****************************************************************\n" ;
bool is_Found = false, Duplicated = false;
string phone;
cout << "Enter Your Contact's Phone that you want to Search: ";
cin >> phone ;
for (int it = 0; it < contacts.size(); it++) {
if (contacts[it].phone == phone || contacts[it].Find_phone(phone)) {
is_Found = true;
if (!Duplicated) {
contacts[it].Show_contact();
Duplicated = true;
} else
cout << " " << contacts[it].id << setw(23) << contacts[it].name << setw(21) << contacts[it].phone << "\n";
}
}
if (!is_Found){
cout << "*****************************************************************\nNo Contact Found with this Phone No.\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_sp ; cin >> Choice_sp ;
if(Choice_sp == 1) Search_ByPhone() ;
else if (Choice_sp == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
Again_SP :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Search for another Contact (Yes or No): " ;
string yes_no_SB ; cin >> yes_no_SB ;
if(lower(yes_no_SB) == "yes"){
Search_ByPhone() ;
}else if(lower(yes_no_SB) == "no"){
Interface() ;
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_SP ;
}
}
void Modify_Contact(){ //Function that Modify a contact
bool is_Found = false ,Same = false ;
string Name , modified_name , modified_phone , choice_modify , Phone ;
int Id ,Press_modify;
system("cls");
cout << "*****************************************************************\n" ;
show_allContact();
cout << "*****************************************************************\n" ;
cout << "1 -> Choose a Contacts that you want Edit with ID:\n" ;
cout << "2 -> Choose a Contacts that you want Edit with Name:\n" ;
cout << "3 -> Choose a Contacts that you want Edit with Phone No.:\n" ;
cout << "4 -> Return to The Main menu\n" ;
cout << "*****************************************************************\n" ;
cout << "Press The Number That You want: " ;
cin >> Press_modify ;
system("cls");
cout << "*****************************************************************\n" ;
if(Press_modify == 1){
cout << "Enter ID of The Contact that you want to Modify:";
cin >> Id;
} else if (Press_modify == 2){
cout << "Enter Name of The Contact that you want to Modify:";
getline(cin,Name) ,getline(cin,Name);
} else if (Press_modify == 3){
cout << "Enter Phone No. of The Contact that you want to Modify:";
cin >> Phone ;
}else if (Press_modify == 4) system("cls"),Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n" ;
cout << "*****************************************************************\n" ;
system("pause");
Modify_Contact() ;
}
cout << "*****************************************************************\n" ;
system("cls");
cout << "*****************************************************************\n" ;
for(int it = 0 ; it < contacts.size() ; it++){
if (lower(contacts[it].name) == lower(Name) || contacts[it].phone == Phone || it + 1 == Id){
is_Found = true ;
cout << "1 -> Edit The Contact's Name: \n" ;
cout << "2 -> Edit The Contact's Phone No: \n" ;
cout << "3 -> Edit Both of The Contact's Name & Phone No: \n" ;
cout << "4 -> Return Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Press The Number That You want: " ;
int press_mod ; cin >> press_mod;
system("cls");
cout << "*****************************************************************\n" ;
if(press_mod == 1){
cout << "Enter The New Name of The Contact: " ;
getline(cin,modified_name),getline(cin,modified_name) ;
}else if (press_mod == 2){
cout << "Enter The New Phone No. of The Contact: ";
cin >> modified_phone ;
}else if (press_mod == 3){
cout << "Enter Contact's New Information\n" ;
cout << "*****************************************************************\n" ;
cout << "Enter The New Name of The Contact: " ; getline(cin,modified_name),getline(cin,modified_name) ;
cout << "Enter The New Phone No. of The Contact: " ; cin >> modified_phone ;
}else if (press_mod == 4) system("cls") ,Interface();
else {
cout << "Not Valid! ... Try Again\n";
cout << "*****************************************************************\n" ;
system("pause");
Modify_Contact() ;
}
for(int k = 0 ; k < modified_name.size() ; k++) {
if (modified_name[0] >= 97 && modified_name[0] <= 122) {
modified_name[0] -= 32;
continue;
}
if (modified_name[k] == ' ') {
if (modified_name[k + 1] >= 97 && modified_name[k + 1] <= 122) modified_name[k + 1] -= 32;
}
}
Contact C1(it + 1 ,modified_name,modified_phone) ;
for(int j = 0 ; j < contacts.size() ;j++){
if(contacts[j].phone == modified_phone){
Same = true ;
break ;
}
}
if(press_mod != 1) {
if (Same) {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... There is a Contact Matched with this Number\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_sn ; cin >> Choice_sn ;
if(Choice_sn == 1) Modify_Contact() ;
else if (Choice_sn == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
}
contacts[it].Show_contact() ;
Choice:
cout << "*****************************************************************\n";
cout << "The Contact that you choose it will be Modified\n" ;
cout << "*****************************************************************\n" ;
cout << "Yes or No: " ; cin >> choice_modify ;
if(lower(choice_modify) == "yes") {
for(int i = 0 ; i < log.size() ;i++){
if((press_mod == 2 || press_mod == 3) && log[i].call.first.phone == contacts[it].phone){
Contact C2 (contacts.size() + 1,"UnKnown",contacts[it].phone) ;
log[i].call.first = C2 ;
}
if(log[i].call.first.phone == contacts[it].phone && log[i].call.first.name != C1.name && press_mod == 1){
Contact C2 (contacts.size() + 1, modified_name, contacts[it].phone);
log[i].call.first = C2 ;
}
}
if (press_mod == 1) contacts[it].name = modified_name ;
else if (press_mod == 2) contacts[it].phone = modified_phone ;
else if (press_mod == 3) contacts[it] = C1 ;
cout << "*****************************************************************\n" ;
cout << "The Contact Modified\n" ;
Swap_Contacts() ;
for(int i = 0 ; i < contacts.size() ; i++){
contacts[i].id = i + 1 ;
}
Again_Modify :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Edit another Contact (Yes or No): " ;
string yes_no_modified ; cin >> yes_no_modified ;
if(lower(yes_no_modified) == "yes"){
Modify_Contact() ;
}else if(lower(yes_no_modified) == "no"){
Interface() ;
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_Modify ;
}
}else if(lower(choice_modify) == "no") {
Interface() ;
}else{
cout << "Not Valid! ... Try Again\n" ;
cout << "*****************************************************************\n" ;
system("pause");
goto Choice ;
}
break ;
}
}
if(!is_Found) {
system("cls");
cout << "*****************************************************************\nNo Contact Matched! ... Try Again\n" ;
cout << "*****************************************************************\n";
system("pause") ;
Modify_Contact();
}
}
void Delete_Contact(){ //Function That Delete Contact by using iterator
string Name , Phone; bool is_Found = false ; int Id , Press_Delete , counter = 0 ;
system("cls");
cout << "*****************************************************************\n" ;
show_allContact() ;
cout << "*****************************************************************\n" ;
cout << "1 -> Choose a Contacts that you want Delete with ID:\n" ;
cout << "2 -> Choose a Contacts that you want Delete with Name:\n" ;
cout << "3 -> Choose a Contacts that you want Delete with Phone No.:\n" ;
cout << "4 -> Return to The Main menu:\n " ;
cout << "*****************************************************************\n" ;
cout << "Press The Number That You want: " ;
cin >> Press_Delete ;
system("cls");
cout << "*****************************************************************\n" ;
if(Press_Delete == 1){
cout << "Enter ID of The Contact that you want to Delete:";
cin >> Id;
} else if (Press_Delete == 2){
cout << "Enter Name of The Contact that you want to Delete:";
getline(cin,Name),getline(cin,Name) ;
} else if (Press_Delete == 3){
cout << "Enter Phone No. of The Contact that you want to Delete:";
cin >> Phone ;
}else if (Press_Delete == 4) system("cls"),Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid ... Try Again\n" ;
cout << "*****************************************************************\n" ;
system("pause");
Delete_Contact();
}
for(auto it = contacts.begin(); it != contacts.end() ; it++ , counter++) {
if (lower(it->name) == lower(Name) || it->phone == Phone || counter + 1 == Id) {
is_Found = true;
it-> Show_contact() ;
Choice:
cout << "*****************************************************************\n";
cout << "The Contact that you choose it will be Deleted\n";
cout << "*****************************************************************\n";
cout << "Yes or No: ";
string choice;
cin >> choice;
if (lower(choice) == "yes") {
cout << "*****************************************************************\n";
cout << "The Contact Deleted\n";
for(int i = 0 ; i < log.size() ; i++){
if(log[i].call.first.phone == contacts[counter].phone){
Contact C1 (contacts.size() + 1,"UnKnown",contacts[counter].phone) ;
log[i].call.first = C1 ;
}
}
contacts.erase(it);
Again_Delete :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Delete another Contact (Yes or No): " ;
string yes_no_Delete ;
cin >> yes_no_Delete ;
if(lower(yes_no_Delete) == "yes"){
Delete_Contact() ;
}else if(lower(yes_no_Delete) == "no"){
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_Delete ;
}
break;
} else if (lower(choice) == "no") {
Interface() ;
} else {
cout << "*****************************************************************\n";
cout << "Not Valid! ... Try Again\n";
cout << "*****************************************************************\n";
system("pause");
goto Choice;
}
}
}
for(int i = 0 ; i < contacts.size() ; i++){
contacts[i].id = i + 1 ;
}
if(!is_Found){
cout << "*****************************************************************\n" << "No Contact Matched! ... Try Again\n" ;
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_sn ; cin >> Choice_sn ;
if(Choice_sn == 1) Delete_Contact() ;
else if (Choice_sn == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
}
void show_allContact() { //Function That Display All Contacts
if (contacts.empty()) {
cout << "No Contacts Found!\n";
} else {
cout << "Information About All Contact is: \n";
cout << "*****************************************************************\n" ;
cout << "||ID||.........|| Name ||.........|| Phone.No ||\n" ;
cout << "*****************************************************************\n" ;
for (int it = 0; it < contacts.size(); it++) {
cout << " " << contacts[it].id << setw(23) << contacts[it].name << setw(21) << contacts[it].phone << "\n" ;
}
}
}
void Delete_Contacts(){ //Function That Delete All Contact
system("cls");
cout << "*****************************************************************\n" ;
cout << "You Are About Delete All The Contacts\n" ;
cout << "*****************************************************************\n" ;
cout << "Yes or No: "; string choice ; cin >> choice ;
if(lower(choice) == "yes") {
contacts.clear();
for(int i = 0 ; i < log.size() ; i++){
log[i].call.first.name = "Un Known" ;
}
cout << "*****************************************************************\n" ;
cout << "All Contacts Deleted\n";
}else if (lower(choice) != "no"){
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
cout << "*****************************************************************\n" ;
system("pause");
Delete_Contacts();
}
}
void call() {
system("cls");
cout << "*****************************************************************\n" ;
string choice_Call ; int Press_Call ; bool same = false ;
Contact C1 ;
cout << "1 -> Call a Number:\n";
cout << "2 -> Call a contact with the Name: \n" ;
cout << "3 -> Return to The Main Menu: \n";
cout << "*****************************************************************\n" ;
cout << "Press the Number that you want to Do: ";
cin >> Press_Call ;
system("cls");
cout << "*****************************************************************\n" ;
if (Press_Call == 1 || Press_Call == 2) {
if (Press_Call == 1) {
cout << "Enter The Number That you want to Call: ";
cin >> choice_Call;
for(int i = 0 ; i < contacts.size() ; i++){
if(contacts[i].phone == choice_Call){
C1 = contacts[i] ;
same = true ;
}
}
if(!same) {
Contact C2(contacts.size() + 1, "UnKnown", choice_Call);
C1 = C2;
}
}
else if (Press_Call == 2) {
cout << "Enter Name of The Contact that you want to Call: ";
getline(cin,choice_Call),getline(cin,choice_Call);
bool is_Found = false;
for (int i = 0; i < contacts.size(); i++) {
if (lower(contacts[i].name) == lower(choice_Call)) {
is_Found = true, same = true ;
C1 = contacts[i] ;
}
}
if (!is_Found) {
cout << "*****************************************************************\n" ;
cout << "No Contact Found!\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_sn ; cin >> Choice_sn ;
if(Choice_sn == 1) call() ;
else if (Choice_sn == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
}
}else if (Press_Call == 3) Interface();
else {
cout << "Not Valid! ... Try Again\n";
system("pause") ;
call() ;
}
cout << "*****************************************************************\n" ;
cout << "Hit 'Enter' to start The Call with " << (same ? C1.name : choice_Call) << "\n" ;
cout << "Hit 'ESC' to stop The Call with " << (same ? C1.name : choice_Call) << "\n" ;
cout << "*****************************************************************\n" ;
cin.get();
unsigned int seconds = 0;
unsigned int minutes = 0;
while (!GetAsyncKeyState(0x1B)) {
seconds++;
if (seconds == 60) {
seconds = 0;
minutes++;
}
Sleep(1000);
}
cout << "The Duration of The Call with " << (same ? C1.name : choice_Call) << " is: " ;
cout << (minutes < 10 ? "0" : "" ) << minutes << ":" << (seconds < 10 ? "0" : "" ) << seconds << "\n";
Duration Time(minutes,seconds);
Call_log log1(C1,Time) ;
log.push_back(log1) ;
Again_Call :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Make another Call (Yes or No): " ;
string yes_no_c ; cin >> yes_no_c ;
if(lower(yes_no_c) == "yes"){
call() ;
}else if(lower(yes_no_c) == "no"){
Interface() ;
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_Call ;
}
}
void Show_Call_log(){
system("cls") ;
if(!log.empty()){
for(int i = 0 ; i < log.size() ; i++){
log[i].call.first.id = i + 1 ;
}
cout << "**************************************************************************\n" ;
cout << "||ID||.........|| Name ||.........|| Phone.No ||.........|| Duration ||\n" ;
cout << "**************************************************************************\n" ;
for(int i = 0 ; i < log.size() ; i++){
log[i].Show_log() ;
}
cout << "**************************************************************************\n\n" ;
}else{
cout << "*****************************************************************\nNo Calls Found!\n";
cout << "*****************************************************************\n" ;
system("pause");
Interface() ;
}
}
void Send_Message(){
system("cls");
cout << "*****************************************************************\n" ;
string choice_message ; int Press_Message; bool same = false ;
cout << "1 -> Send a Message to any Number:\n";
cout << "2 -> Send a Message to a contact with the Name: \n" ;
cout << "3 -> Return to The Main Menu: \n";
cout << "*****************************************************************\n" ;
cout << "Press the Number that you want to Do: ";
cin >> Press_Message ;
system("cls");
cout << "*****************************************************************\n" ;
if (Press_Message == 1 || Press_Message == 2) {
if (Press_Message == 1) {
cout << "Enter The Number That you want to send a Message: ";
cin >> choice_message;
} else if (Press_Message == 2) {
cout << "Enter Name of The Contact that you want to send a Message: ";
getline(cin,choice_message) ,getline(cin,choice_message);
bool is_Found = false;
for (int i = 0; i < contacts.size(); i++) {
if (lower(contacts[i].name) == lower(choice_message)) {
is_Found = true;
}
}
if (!is_Found) {
cout << "*****************************************************************\n" ;
cout << "No Contact Found With This Name\n";
Try:
cout << "*****************************************************************\n" ;
cout << "1 -> Try Again\n";
cout << "2 -> Return To Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Enter Your Choice: " ;
int Choice_sn ; cin >> Choice_sn ;
if(Choice_sn == 1) Send_Message() ;
else if (Choice_sn == 2) Interface() ;
else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! ... Try Again\n";
goto Try ;
}
}
}
}else if (Press_Message == 3) system("cls"),Interface();
else {
cout << "Not Valid ... Try Again\n";
cout << "*****************************************************************\n" ;
system("pause");
Send_Message() ;
}
system("cls");
cout << "*****************************************************************\n" ;
cout << "Enter The Message that you want to send:\n";
cout << "*****************************************************************\n" ;
string Message ;
if(Press_Message == 1) getline(cin,Message) ;
getline(cin,Message) ;
cout << "*****************************************************************\n" ;
cout << "Message Sent!\n" ;
Again_Message :
cout << "*****************************************************************\n" ;
cout << "Do You Want to Send another Message (Yes or No): " ;
string yes_no_m ; cin >> yes_no_m ;
if(lower(yes_no_m) == "yes"){
Send_Message() ;
}else if(lower(yes_no_m) == "no"){
Interface() ;
}else {
cout << "*****************************************************************\n" ;
cout << "Not Valid! .. Try Again\n" ;
goto Again_Message ;
}
}
void Delete_Call_log() {
if(log.empty()) {
system("cls");
cout << "*****************************************************************\n";
cout << "No Call Found!\n", Interface();
}
system("cls");
cout << "*****************************************************************\n";
cout << "You Are About Delete The Call Log\n";
cout << "*****************************************************************\n";
cout << "Yes or No: ";
string yes_no_dl;
cin >> yes_no_dl;
if (lower(yes_no_dl) == "yes") {
log.clear();
cout << "*****************************************************************\n";
cout << "Call Log Deleted\n";
} else if (lower(yes_no_dl) == "no") {
system("cls");
Interface();
} else {
cout << "Not Valid! ... Try Again\n";
cout << "*****************************************************************\n";
system("pause");
Delete_Call_log();
}
}
void Interface(){ //The Interface of The Program
system("color f6");
system("cls") ;
cout << "*****************************************************************\n" ;
cout << "************************|| Phone Book ||*************************\n" ;
cout << "1 -> Display All The Contacts\n" ;
cout << "2 -> Add\n" ;
cout << "3 -> Search\n" ;
cout << "4 -> Delete\n" ;
cout << "5 -> Edit\n" ;
cout << "6 -> Call\n" ;
cout << "7 -> Send a Message\n" ;
cout << "8 -> Exit\n" ;
cout << "*****************************************************************\n" ;
cout << "Press the Number that you want to Do: ";
int main_key ;
cin >> main_key ;
system("cls");
cout << "*****************************************************************\n" ;
if (main_key == 1) show_allContact() ;
else if (main_key == 2) New_Contact();
else if (main_key == 3){
Again:
system("cls");
if (!contacts.empty()) {
int search_choice;
cout << "*****************************************************************\n";
cout << "1 -> Search A Contact By ID\n";
cout << "2 -> Search A Contact By Name\n";
cout << "3 -> Search A Contact By Phone.No\n";
cout << "4 -> Return to The Main Menu\n";
cout << "*****************************************************************\n";
cout << "Press The Number of The Way that You Want to Search By it: ";
cin >> search_choice ;
cout << "*****************************************************************\n";
if (search_choice == 1) Search_ByID();
else if (search_choice == 2) Search_ByName();
else if (search_choice == 3) Search_ByPhone();
else if (search_choice == 4) Interface();
else {
cout << "Not Valid ... Try Again\n";
cout << "*****************************************************************\n";
system("pause");
goto Again;
}
} else {
cout << "*****************************************************************\n" ;
cout << "No Contacts Found!\n";
cout << "*****************************************************************\n" ;
system("pause");
Interface() ;
}
}else if (main_key == 4) {
Again_2:
system("cls");
cout << "*****************************************************************\n" ;
if (!contacts.empty()) {
int delete_choice;
cout << "1 -> Delete a Contact\n";
cout << "2 -> Delete All The Contacts\n";
cout << "3 -> Return to The Main Menu\n";
cout << "*****************************************************************\n" ;
cout << "Press The Number that you Want: ";
cin >> delete_choice ;
cout << "*****************************************************************\n" ;
if (delete_choice == 1) Delete_Contact();
else if (delete_choice == 2) Delete_Contacts();
else if (delete_choice == 3) system("cls"),Interface();
else {
cout << "Not Valid! ... Try Again\n";
cout << "*****************************************************************\n" ;
system("pause");
goto Again_2 ;
}
}else {
cout << "No Contacts Found!\n" ;
cout << "*****************************************************************\n" ;
system("pause");
Interface() ;
}
}
else if (main_key == 5) {
if(!contacts.empty()) {
Modify_Contact();
}else cout << "No Contacts Found!\n" ;
}
else if (main_key == 6) {
Again_3 :
system("cls");
cout << "*****************************************************************\n" ;
cout << "1 -> Make a Call\n";
cout << "2 -> Display Call Log\n" ;
cout << "3 -> Delete Call Log\n" ;
cout << "4 -> Return to The Main Menu\n" ;
cout << "*****************************************************************\n" ;
cout << "Press The Number that you Want: ";
int call_choice ; cin >> call_choice ;
system("cls");
cout << "*****************************************************************\n" ;
if(call_choice == 1) call() ;
else if (call_choice == 2) {
Show_Call_log() ;
system("pause");
Interface() ;
}
else if (call_choice == 3) Delete_Call_log() ;
else if (call_choice == 4) Interface();
else {
cout << "*****************************************************************\nNot Valid! ... Try Again\n";
cout << "*****************************************************************\n" ;
system("pause");
goto Again_3 ;
}
}
else if (main_key == 7) Send_Message();
else if (main_key == 8) {
End = true ;
system("cls");
cout << "*****************************************************************\n" ;
cout << "Contact Us\n" ;
cout << "*****************************************************************\n" ;
cout << "Name: Ahmed HoSSam\n" ;
cout << "Phone No: 01208822340\n" ;
cout << "*****************************************************************\n" ;
cout << " ###### \n"
"## ## ## ## \n"
"## ## ## \n"
"## ###### ###### \n"
"## ## ## \n"
"## ## ## ## \n"
" ###### \n" ;
cout << "*****************************************************************\n" ;
update_Contacts(),update_Calls() ;
exit(0);
}
else cout << "Not Valid ... Try Again\n" ;
cout << "*****************************************************************\n" ;
system("pause");
Interface() ;
}
};
int main(){
system("color f7") ;
PhoneBook_System PhoneBook ;
while(!PhoneBook.End){
PhoneBook.Interface() ;
}
} //Thnak You ♥♥