aboutsummaryrefslogtreecommitdiff
path: root/Project1/program.cpp
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-21 16:51:29 -0800
committerConnor McDowell <[email protected]>2024-02-21 16:51:29 -0800
commit2f564c37810887b388bacd7d4fff2f438b0e4a67 (patch)
tree83db4e8145c05861a992a6bcd8fe5c322bb011c4 /Project1/program.cpp
parentgunna call it and talk with prof during office hours (diff)
downloadhomework-6-connormcdowell275-2f564c37810887b388bacd7d4fff2f438b0e4a67.tar.xz
homework-6-connormcdowell275-2f564c37810887b388bacd7d4fff2f438b0e4a67.zip
doubling working now
Diffstat (limited to 'Project1/program.cpp')
-rw-r--r--Project1/program.cpp52
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;