aboutsummaryrefslogtreecommitdiff
path: root/Homework6
diff options
context:
space:
mode:
authorYana Blashchishina <[email protected]>2024-02-19 17:06:55 -0800
committerYana Blashchishina <[email protected]>2024-02-19 17:06:55 -0800
commitee439e43761cd5f7b8706d7677079bd2d3319af8 (patch)
tree5dbcca369780ba1c386ee3474826707238ec6f4b /Homework6
parentheader updated (diff)
downloadhomework-6-yanablash-ee439e43761cd5f7b8706d7677079bd2d3319af8.tar.xz
homework-6-yanablash-ee439e43761cd5f7b8706d7677079bd2d3319af8.zip
addContact updated
Diffstat (limited to 'Homework6')
-rw-r--r--Homework6/Homework6/contacts.cpp17
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;
- }
+
}