-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
AddressBook.cpp
70 lines (60 loc) · 1.76 KB
/
AddressBook.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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Contact {
string name;
string phoneNumber;
};
class AddressBook {
private:
vector<Contact> contacts;
public:
void addContact(const string& name, const string& phoneNumber) {
Contact newContact;
newContact.name = name;
newContact.phoneNumber = phoneNumber;
contacts.push_back(newContact);
cout << "Contact added: " << name << ", " << phoneNumber << endl;
}
void displayContacts() {
cout << "Address Book:" << endl;
for (const Contact& contact : contacts) {
cout << "Name: " << contact.name << ", Phone: " << contact.phoneNumber << endl;
}
}
};
int main() {
AddressBook addressBook;
while (true) {
cout << "Address Book Application" << endl;
cout << "1. Add Contact" << endl;
cout << "2. Display Contacts" << endl;
cout << "3. Quit" << endl;
cout << "Enter your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1: {
cout << "Enter contact name: ";
cin.ignore();
string name;
getline(cin, name);
cout << "Enter phone number: ";
string phoneNumber;
cin >> phoneNumber;
addressBook.addContact(name, phoneNumber);
break;
}
case 2:
addressBook.displayContacts();
break;
case 3:
cout << "Exiting the Address Book Application. Goodbye!" << endl;
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
}
}
return 0;
}