diff options
| author | Yana Blashchishina <[email protected]> | 2024-02-19 17:20:33 -0800 |
|---|---|---|
| committer | Yana Blashchishina <[email protected]> | 2024-02-19 17:20:33 -0800 |
| commit | bb5178a6eaab78cf6c5ac1dcac4a957802625dd4 (patch) | |
| tree | 3a608653c417168ccb3e7fc2fc7b43cf73251739 /Homework6 | |
| parent | updateContact updated (diff) | |
| download | homework-6-yanablash-bb5178a6eaab78cf6c5ac1dcac4a957802625dd4.tar.xz homework-6-yanablash-bb5178a6eaab78cf6c5ac1dcac4a957802625dd4.zip | |
contacts.h fixed
Diffstat (limited to 'Homework6')
| -rw-r--r-- | Homework6/Homework6/contacts.cpp | 28 | ||||
| -rw-r--r-- | Homework6/Homework6/contacts.h | 4 |
2 files changed, 29 insertions, 3 deletions
diff --git a/Homework6/Homework6/contacts.cpp b/Homework6/Homework6/contacts.cpp index 4caac14..c4ee25c 100644 --- a/Homework6/Homework6/contacts.cpp +++ b/Homework6/Homework6/contacts.cpp @@ -83,7 +83,7 @@ void printContact(const Contact contacts[], int numContacts) { cout << "No contacts available"; } else { - cout << "Contacts: "; + cout << "Contacts: " << endl; for (int i = 0; i < numContacts; ++i) { const Contact& contact = contacts[i]; cout << "Name: " << contact.Name << " x "; @@ -94,4 +94,30 @@ void printContact(const Contact contacts[], int numContacts) { cout << " Zip Code: " << contact.Zip << " x "; } } +} + + +void deleteContact(const Contact contacts[], int& numContacts) { + printContact(contacts, numContacts); + + if (numContacts > 0) { + int num; + cout << "enter the number of the contact to delete: "; + cin >> num; + + if (num >= 0 && num < numContacts) { + for (int i = num; i < numContacts - 1; ++i) { + contacts[i] = contacts[i + 1]; + } + numContacts; + cout << "contact deleted" << endl; + } + else { + cout << "invalid" << endl; + } + + } + else { + cout << "no contacts available" << endl; + } }
\ No newline at end of file diff --git a/Homework6/Homework6/contacts.h b/Homework6/Homework6/contacts.h index 65b3529..876dd5a 100644 --- a/Homework6/Homework6/contacts.h +++ b/Homework6/Homework6/contacts.h @@ -10,8 +10,8 @@ struct Contact { int Zip = 0; }; -void addContact(Contact contacts[], int& numContacts); +void addContact(Contact contacts[], int& numContacts, int& arraySize); void updateContact(Contact contacts[], int& numContacts); void printContact(const Contact contacts[], int numContacts); -void deleteContact(const Contact contacts[], int numContacts); +void deleteContact(Contact contacts[], int& numContacts); #endif
\ No newline at end of file |