From 2f564c37810887b388bacd7d4fff2f438b0e4a67 Mon Sep 17 00:00:00 2001 From: Connor McDowell Date: Wed, 21 Feb 2024 16:51:29 -0800 Subject: doubling working now --- Project1/contacts.cpp | 52 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'Project1/contacts.cpp') diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 4c9814b..e542d64 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -116,33 +116,43 @@ 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; ++a) + //{ + // doubleContact[a].a = newContact[a].a; + // doubleContact[a].id = newContact[a].id; + // doubleContact[a].count = newContact[a].count; + // doubleContact[a].Name[25] = newContact[a].Name[25]; + // doubleContact[a].Email[100] = newContact[a].Email[100]; + // doubleContact[a].StreetAddress[35] = newContact[a].StreetAddress[35]; + // doubleContact[a].City[30] = newContact[a].City[30]; + // doubleContact[a].State[3] = newContact[a].State[3]; + // doubleContact[a].Zip = newContact[a].Zip; + // cout << "List number: " << doubleContact[a].id << endl; + // cout << "name: " << doubleContact[a].Name << endl; + // cout << "Email: " << doubleContact[a].Email << endl; + // cout << "Address: " << doubleContact[a].StreetAddress << endl; + // cout << "city: " << doubleContact[a].City << endl; + // cout << "state: " << doubleContact[a].State << endl; + // cout << "Zip: " << doubleContact[a].Zip << endl; + //} + //newContact = doubleContact; + //delete[] doubleContact; + ////delete[] newContact; + //MAX = MAX * 2; + ////printAll(&doubleContact[MAX], MAX); + ////printAll(&newContact[MAX], MAX); + //return newContact[MAX]; + contact* doubleContact = new contact[MAX * 2]; for (auto a = 0u; a < MAX; ++a) { - doubleContact[a].a = newContact[a].a; - doubleContact[a].id = newContact[a].id; - doubleContact[a].count = newContact[a].count; - doubleContact[a].Name[30] = newContact[a].Name[30]; - doubleContact[a].Email[100] = newContact[a].Email[100]; - doubleContact[a].StreetAddress[35] = newContact[a].StreetAddress[35]; - doubleContact[a].City[30] = newContact[a].City[30]; - doubleContact[a].State[3] = newContact[a].State[3]; - doubleContact[a].Zip = newContact[a].Zip; - cout << "List number: " << doubleContact[a].id << endl; - cout << "name: " << doubleContact[a].Name << endl; - cout << "Email: " << doubleContact[a].Email << endl; - cout << "Address: " << doubleContact[a].StreetAddress << endl; - cout << "city: " << doubleContact[a].City << endl; - cout << "state: " << doubleContact[a].State << endl; - cout << "Zip: " << doubleContact[a].Zip << endl; + doubleContact[a] = newContact[a]; } + delete[] newContact; newContact = doubleContact; - delete[] doubleContact; - //delete[] newContact; MAX = MAX * 2; - //printAll(&doubleContact[MAX], MAX); - //printAll(&newContact[MAX], MAX); - return newContact[MAX]; + return newContact[MAX - 1]; } size_t max_double(size_t MAX) -- cgit v1.2.3