-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.cpp
More file actions
145 lines (145 loc) · 3.34 KB
/
Copy pathproject.cpp
File metadata and controls
145 lines (145 loc) · 3.34 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
#include <iostream>
#include <vector>
using namespace std;
class Contact {
public:
string name, phone, email, priority;
Contact(string n, string p, string e, string pr) {
name = n;
phone = p;
email = e;
priority = pr;
}
};
class ContactManager {
private:
vector<Contact> contacts;
public:
void addContact(string name, string phone, string email, string priority) {
contacts.push_back(Contact(name, phone, email, priority));
cout << "\nContact Added Successfully\n";
}
void viewContacts() {
if (contacts.empty()) {
cout << "\nNo Contacts Found\n";
return;
}
cout << "\n========== CONTACT LIST ==========\n";
for (auto c : contacts) {
cout << "\n------------------------------\n";
cout << "Name : " << c.name << endl;
cout << "Phone : " << c.phone << endl;
cout << "Email : " << c.email << endl;
cout << "Priority : " << c.priority << endl;
cout << "------------------------------\n";
}
}
// SMART SEARCH (partial match)
void searchContact(string key) {
bool found = false;
for (auto c : contacts) {
if (c.name.find(key) != string::npos) {
cout << "\n----- Contact Found -----\n";
cout << "Name : " << c.name << endl;
cout << "Phone : " << c.phone << endl;
cout << "Email : " << c.email << endl;
cout << "Priority : " << c.priority << endl;
cout << "-------------------------\n";
found = true;
}
}
if (!found)
cout << "\nContact Not Found\n";
}
void updateContact(string name, string phone, string email, string priority) {
for (auto &c : contacts) {
if (c.name == name) {
c.phone = phone;
c.email = email;
c.priority = priority;
cout << "\nContact Updated\n";
return;
}
}
cout << "\nContact Not Found\n";
}
void deleteContact(string name) {
for (int i = 0; i < contacts.size(); i++) {
if (contacts[i].name == name) {
contacts.erase(contacts.begin() + i);
cout << "\nContact Deleted\n";
return;
}
}
cout << "\nContact Not Found\n";
}
};
int main() {
ContactManager cm;
int choice;
string name, phone, email, priority;
// PASSWORD SECURITY
string password = "contacts@4287", input;
cout << "Enter Password: ";
cin >> input;
if (input != password) {
cout << "Access Denied!\n";
return 0;
}
cout << "\nAccess Granted!\n";
while (true) {
cout << "\n==============================\n";
cout << " CONTACT MANAGEMENT SYSTEM \n";
cout << "==============================\n";
cout << "1. Add Contact\n";
cout << "2. View Contacts\n";
cout << "3. Search Contact\n";
cout << "4. Update Contact\n";
cout << "5. Delete Contact\n";
cout << "6. Exit\n";
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "\nEnter Name: ";
cin >> name;
cout << "Enter Phone: ";
cin >> phone;
cout << "Enter Email: ";
cin >> email;
cout << "Enter Priority (High/Medium/Low): ";
cin >> priority;
cm.addContact(name, phone, email, priority);
break;
case 2:
cm.viewContacts();
break;
case 3:
cout << "\nEnter Name to search: ";
cin >> name;
cm.searchContact(name);
break;
case 4:
cout << "\nEnter Name to update: ";
cin >> name;
cout << "Enter New Phone: ";
cin >> phone;
cout << "Enter New Email: ";
cin >> email;
cout << "Enter New Priority: ";
cin >> priority;
cm.updateContact(name, phone, email, priority);
break;
case 5:
cout << "\nEnter Name to delete: ";
cin >> name;
cm.deleteContact(name);
break;
case 6:
cout << "\nExiting Program...\n";
return 0;
default:
cout << "\nInvalid Choice\n";
}
}
}