diff options
| -rw-r--r-- | Homework6/Homework6/contacts.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Homework6/Homework6/contacts.cpp b/Homework6/Homework6/contacts.cpp index 0e7a19d..8d6cb96 100644 --- a/Homework6/Homework6/contacts.cpp +++ b/Homework6/Homework6/contacts.cpp @@ -6,8 +6,19 @@ using std::cout; using std::cin; using std::endl; -void addContact(Contact contacts[], int& numContacts) { - if (numContacts < 100) { +void addContact(Contact contacts[], int& numContacts,int& arraySize) { + if (numContacts >= arraySize) { + arraySize *= 2; + + Contact* newContacts = new Contact[arraySize]; + for (int i = 0; i < numContacts; ++i) { + newContacts[i] = contacts[i]; + } + delete[] contacts; + + contacts = newContacts; + } + Contact& newContact = contacts[numContacts]; cout << "Enter Name: "; @@ -27,7 +38,7 @@ void addContact(Contact contacts[], int& numContacts) { cout << "Enter Zip Code: "; cin >> newContact.Zip; - } + } |