diff options
| author | Connor McDowell <[email protected]> | 2024-02-26 14:45:17 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-26 14:45:17 -0800 |
| commit | 6f9a49f95cf3ca9e518bc460f7458719b43793b0 (patch) | |
| tree | f4979539ca12bf4b85c553cbb422b31a124cf642 /Project1/program.cpp | |
| parent | add deadline (diff) | |
| download | homework-7-connormcdowell275-6f9a49f95cf3ca9e518bc460f7458719b43793b0.tar.xz homework-7-connormcdowell275-6f9a49f95cf3ca9e518bc460f7458719b43793b0.zip | |
added menu driven address book from assignment 6
Diffstat (limited to 'Project1/program.cpp')
| -rw-r--r-- | Project1/program.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Project1/program.cpp b/Project1/program.cpp new file mode 100644 index 0000000..ef06d25 --- /dev/null +++ b/Project1/program.cpp @@ -0,0 +1,67 @@ +// name: Connor McDowell +// date: 2/19/2024 +// class: CST116 +// reason: homework number 6 + +#include "Contacts.h" +#include <iostream> + +using std::cin; +using std::cout; +using std::endl; + +//constexpr size_t MAX = 3; + +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[MAX]) << 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"; + cout << "3. print all contacts\n"; + cout << "4. Delete a contact\n"; + cout << "5. Quit\n"; + cout << "\nEnter your choice: " << endl; + cin >> c; + switch (c) + { + case 1: + addNew(newContact, MAX, 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, MAX); // Print only the existing contacts + break; + case 4: + delete_contact(newContact, MAX); + break; + case 5: + O = 0; + break; + default: + cout << "Invalid choice. Please enter a number from 1 to 5." << endl; + } + } + return 0; +}
\ No newline at end of file |