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
|
#include <iostream>
#include <string>
using namespace std;
constexpr size_t MaxEntry {10};
struct Contact {
string name;
string address;
string phone;
Contact() {}
Contact(const string& nam, const string& addr, const string& pho) : name(nam), address(addr), phone(pho) {}
};
int main() {
Contact phonebook[MaxEntry] {};
size_t entries {4};
phonebook[0] = Contact("Daniel Pettersson", "Dreamgate 47", "123456789");
phonebook[1] = Contact("Didrik Petrovic", "Kvarter Guldbaggen 8", "987654321");
phonebook[2] = Contact("Dan Pettson", "Guldbaggegatan 8", "246897531");
phonebook[3] = Contact("David Persson", "Guldbaggevaegen 8", "135798642");
for (char menuSelection {}; menuSelection != '5'; ) {
cout << "\n-------------------Welcome to your Phone book!-------------------\n";
cout << "--------------------What do you want to do?-------------------\n";
cout << "\nPress [1] to see all contacts\n";
cout << "Press [2] to add a contact\n";
cout << "Press [3] to search a contact\n";
cout << "Press [4] to delete a contact\n";
cout << "Press [5] to exit your phone book\n";
cout << "Enter option: ";
cin >> menuSelection;
cin.ignore();
switch (menuSelection) {
case '1':
for (size_t i {}; i < entries; ++i) {
cout << "\nContact " << i + 1 << '\n';
cout << "Name: " << phonebook[i].name << '\n';
cout << "Address: " << phonebook[i].address << '\n';
cout << "Phone: " << phonebook[i].phone << '\n';
}
break;
case '2':
if (entries < MaxEntry) {
cout << "Add a contact\n";
cout << "Contact " << entries << '\n';
cout << "Name: ";
getline(cin, phonebook[entries].name);
cout << "Address: ";
getline(cin, phonebook[entries].address);
cout << "Phone number: ";
getline(cin, phonebook[entries].phone);
++entries;
} else
cout << "Phone book full\n";
break;
case '3':
cout << "Search a contact\n";
break;
case '4':
cout << "Delete a contact\n";
break;
case '5':
cout << "Good bye\n";
break;
default:
cout << "Invalid option. Please try again\n";
break;
}
}
}
|