diff options
| author | Connor McDowell <[email protected]> | 2024-02-21 16:51:29 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-21 16:51:29 -0800 |
| commit | 2f564c37810887b388bacd7d4fff2f438b0e4a67 (patch) | |
| tree | 83db4e8145c05861a992a6bcd8fe5c322bb011c4 /Project1/program.cpp | |
| parent | gunna call it and talk with prof during office hours (diff) | |
| download | homework-6-connormcdowell275-2f564c37810887b388bacd7d4fff2f438b0e4a67.tar.xz homework-6-connormcdowell275-2f564c37810887b388bacd7d4fff2f438b0e4a67.zip | |
doubling working now
Diffstat (limited to 'Project1/program.cpp')
| -rw-r--r-- | Project1/program.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/Project1/program.cpp b/Project1/program.cpp index acf6c8a..a75931b 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -33,33 +33,35 @@ int main() cout << "5. Quit\n"; cout << "\nEnter your choice: " << endl; cin >> c; - if (t == MAX) - { - newContact[MAX] = contact_double(newContact, MAX, t); - //MAX = max_double(MAX); - } - if (c == 1) - { - addNew(&newContact[MAX], MAX, t); - //cout << t << endl; - } - if (c == 2) - { - update(&newContact[MAX], MAX); - } - if (c == 3) - { - printAll(&newContact[MAX], MAX); - } - if (c == 4) - { - delete_contact(&newContact[MAX]); - } - if (c == 5) + switch (c) { + case 1: + addNew(newContact, MAX, t); + ++t; + if (t >= MAX) // Check if the number of contacts exceeds MAX + { + contact* newContactTemp = new contact[MAX * 2]; // Double the size + for (size_t i = 0; i < MAX; ++i) // Copy existing contacts + newContactTemp[i] = newContact[i]; + delete[] newContact; // Deallocate old memory + newContact = newContactTemp; // Update pointer + MAX *= 2; // Update MAX + } + break; + case 2: + update(newContact, MAX); + break; + case 3: + printAll(newContact, t); // Print only the existing contacts + break; + case 4: + delete_contact(newContact); + break; + case 5: O = 0; - delete[] newContact; - //abort; + break; + default: + cout << "Invalid choice. Please enter a number from 1 to 5." << endl; } } return 0; |