-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
125 lines (98 loc) · 3.06 KB
/
main.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
/*
Name : Aarti Rathi
Wesbite : https://shinchancode.github.io/3d-react-portfolio/
*/
#include<bits/stdc++.h>
#include "Trie.cpp"
#include<windows.h>
using namespace std;
int menu()
{
cout<<"\n";
cout<<"\t\t\t\t\t--------------------------------------------\n";
cout<<"\t\t\t\t\t| PHONE BOOK APPLICATION |\n";
cout<<"\t\t\t\t\t--------------------------------------------\n";
cout<<"\t\t\t\t\t| |\n";
cout<<"\t\t\t\t\t| [1] Add Contacts |\n";
cout<<"\t\t\t\t\t| [2] Search by Name |\n";
cout<<"\t\t\t\t\t| [3] Search by Prefix |\n";
cout<<"\t\t\t\t\t| [4] Delete Data |\n";
cout<<"\t\t\t\t\t| [5] Show Prefixes |\n";
cout<<"\t\t\t\t\t| |\n";
cout<<"\t\t\t\t\t--------------------------------------------\n";
cout<<"\t\t\t\t\t| [6] Exit |\n";
cout<<"\t\t\t\t\t--------------------------------------------\n";
cout<<"\n";
cout<<"\t\t\t\t\tEnter your choice : ";
int choice;
cin>>choice;
return choice;
}
int main()
{
Trie *t = new Trie();
int choice = menu();
do
{
if(choice==1)
{
cout<<"\t\t\t\t\t\t Please Enter Name : ";
string s,num;
cin>>s;
cout<<"\t\t\t\t\t\t Please Enter Contact No : ";
cin>>num;
if(t->search(s))
{
cout<<"\n\t\t\t\t\t\t Data already exists\n";
}
else
{
t->insert(s, num);
}
}
else if(choice==2)
{
cout<<"\t\t\t\t\t\t Please Enter name to check: ";
string s;
cin>>s;
bool ok = t->search(s);
if(ok)
cout<<"\n\t\t\t\t\t\t Contact exists \n";
else
cout<<"\n\t\t\t\t\t\t Contact does not exist !! \n";
}
else if(choice==3)
{
cout<<"\t\t\t\t\t\t Please Enter prefix to check: ";
string s;
cin>>s;
bool ok = t->starts_with(s);
if(ok)
cout<<"\n\t\t\t\t\t\t Contact exists with this prefix!! \n";
else
cout<<"\n\t\t\t\t\t\t Contact does not exist with this prefix!! \n";
}
else if(choice==4)
{
cout<<"\t\t\t\t\t\t Please Enter name to delete : ";
string n;
cin>>n;
t->remove(n);
}
else if(choice==5)
{
cout<<"\t\t\t\t\t\t Please Enter the prefix: ";
string na;
cin>>na;
t->show_recommendations(na);
}
else
{
break;
}
choice=menu();
}
while(choice<=5 && choice>=1);
cout<<"\n\t\t\t\t\t\t\tTHANK YOU !";
return 0;
}