-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleAddressBook.cpp
More file actions
75 lines (71 loc) · 2.46 KB
/
Copy pathSimpleAddressBook.cpp
File metadata and controls
75 lines (71 loc) · 2.46 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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string> contacts;
while(true)
{
string userChoice;
cout << "Welcome to your Adress book!\nWhat do you want to do?\n";
cout << "| List | Lists all users |\n| Add | Adds an user |\n| Delete | Deletes an user |\n| Delete all | Removes all users |\n| Search | Search or a user |\n| Close | Closes the addgess book |\n";
getline(cin, userChoice);
if(userChoice == "list" or userChoice == "List")
{
if(contacts.empty() == true)
{
cout << "No users found!" << endl;
}
else
{
for(int i = 0; i < contacts.size(); i++)
{
cout << contacts[i] << endl;
}
}
}
else if (userChoice == "add" or userChoice == "Add") {
string newUser;
cout << "Enter the user you want to add: " << endl;
getline(cin, newUser);
contacts.push_back(newUser);
cout << "User Added!" << endl;
}
else if (userChoice == "delete" or userChoice == "Delete") {
string delUser;
cout << "Enter the user you want to delete: " << endl;
getline(cin, delUser);
contacts.erase(remove(contacts.begin(), contacts.end(), delUser), contacts.end());
cout << "User deleted!" << endl;
}
else if (userChoice == "delete all" or userChoice == "Delete all") {
contacts.clear();
cout << "All the users deleted!" << endl;
}
else if (userChoice == "search" or userChoice == "Search") {
string searchUser;
cout << "Enter the user you want to search for: " << endl;
getline(cin, searchUser);
if(find(contacts.begin(), contacts.end(), searchUser) != contacts.end())
{
cout << "Contact is found!" << endl;
}
else
{
cout << "Contact is not found!" << endl;
}
}
else if (userChoice == "close" or userChoice == "Close")
{
cout << "Closing..." << endl;
break;
}
else
{
cout << "Undefined action, please try again!" << endl;
}
}
return 0;
}