diff options
| author | Connor McDowell <[email protected]> | 2024-02-21 15:10:01 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-21 15:10:01 -0800 |
| commit | ed19ed0912533a3e823938542ad5b4d58e93b03a (patch) | |
| tree | c527c3788972abc773a6a57dc5cdc94483c46b61 | |
| parent | share push (diff) | |
| download | homework-6-connormcdowell275-ed19ed0912533a3e823938542ad5b4d58e93b03a.tar.xz homework-6-connormcdowell275-ed19ed0912533a3e823938542ad5b4d58e93b03a.zip | |
still testing
| -rw-r--r-- | Project1/Contacts.h | 4 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 15 | ||||
| -rw-r--r-- | Project1/program.cpp | 10 |
3 files changed, 22 insertions, 7 deletions
diff --git a/Project1/Contacts.h b/Project1/Contacts.h index a1ef0fb..ba605fc 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -29,7 +29,9 @@ void update(contact newContact[], size_t MAX); void printAll(contact newContact[], size_t MAX); -void contact_double(contact*& newContact, size_t& MAX, size_t t); +contact contact_double(contact*& newContact, size_t& MAX, size_t t); + +size_t max_double(size_t MAX); void delete_contact(contact newContact[]); diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 828bef5..162d30b 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -110,20 +110,27 @@ void printAll(contact newContact[], size_t MAX) } } -void contact_double(contact*& newContact, size_t& MAX, size_t t) +contact contact_double(contact*& newContact, size_t& MAX, size_t t) { //supposedly doubles length. doesn't work. //current ideas: add if loop to whole main with the id counter t and if length of newContact = max double the length. //current problems: using const size_t max prevents editing size for the whole function, and it resets as soon as the while loop loops or leaves the scope of the if statement. contact* doubleContact = new contact[MAX * 2]; - for (auto a = 0u; a < MAX * 2; ++a) + for (auto a = 0u; a < MAX; ++a) { doubleContact[a] = newContact[a]; } - delete[] newContact; newContact = doubleContact; + delete[] doubleContact; MAX = MAX * 2; - //return newContact[MAX]; + printAll(&newContact[MAX], MAX); + return newContact[MAX]; +} + +size_t max_double(size_t MAX) +{ + MAX = MAX * 2; + return MAX; } void delete_contact(contact newContact[]) diff --git a/Project1/program.cpp b/Project1/program.cpp index 8b542f1..1f6c0c4 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -16,10 +16,15 @@ int main() { size_t MAX = 3; int O = 1; + /* t = index counter*/ size_t t = 0; contact* newContact = new contact[MAX]; + int length = sizeof(newContact[MAX]); + cout << sizeof(newContact) << endl; while (O == 1) { + cout << MAX << endl; + // c = choice input int c = 0; cout << "1. Enter a contact\n"; cout << "2. Update a contact\n"; @@ -28,7 +33,6 @@ int main() cout << "5. Quit\n"; cout << "\nEnter your choice: " << endl; cin >> c; - //c = menu(); if (c == 1) { addNew(&newContact[MAX], MAX, t); @@ -50,11 +54,13 @@ int main() { O = 0; delete[] newContact; + //abort; } ++t; if (t >= MAX) { - contact_double(newContact, MAX, t); + newContact[MAX] = contact_double(newContact, MAX, t); + //MAX = max_double(MAX); } } return 0; |