diff options
| author | Connor McDowell <[email protected]> | 2024-02-18 14:25:42 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-18 14:25:42 -0800 |
| commit | 13fbf63f860ad74bbf0e941a8b7d953a1e163b7c (patch) | |
| tree | 208485ecae6dc1f95408a9786e6ef0081f4420b4 | |
| parent | still sorting out errors (diff) | |
| download | homework-5-connormcdowell275-13fbf63f860ad74bbf0e941a8b7d953a1e163b7c.tar.xz homework-5-connormcdowell275-13fbf63f860ad74bbf0e941a8b7d953a1e163b7c.zip | |
after all the testing ive more or less reverted back to what ive done. i have no idea how to complete this at this point without a dynamic array and then it pushes into assignment 6.
| -rw-r--r-- | Project1/Contacts.h | 6 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 56 | ||||
| -rw-r--r-- | Project1/program.cpp | 16 |
3 files changed, 41 insertions, 37 deletions
diff --git a/Project1/Contacts.h b/Project1/Contacts.h index 76b66cf..841233d 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -16,12 +16,14 @@ struct contact int Zip = 0; }; +//contact newContact[11]; + int menu(); -char addNew(contact* newContact, size_t MAX); +char addNew(contact newContact, size_t MAX); -void update(contact* newContact, size_t MAX); +void update(contact newContact, size_t MAX); void printAll(contact newContact, size_t MAX); diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 6f29040..29b2f47 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -7,8 +7,6 @@ using std::cin; using std::cout; using std::endl; -constexpr int MAX = 100; - int menu() { int c; @@ -24,7 +22,7 @@ int menu() return c; } -char addNew(contact* newContact, size_t MAX) +char addNew(contact newContact[], size_t MAX) { int i = 0; @@ -35,19 +33,19 @@ char addNew(contact* newContact, size_t MAX) cout << "works!" << endl; for (int i = 0; i < MAX; i++) { - newContact->id = i + 1; + newContact[i].id = i + 1; cout << "enter name: " << endl; - cin >> newContact->Name; + cin >> newContact[i].Name; cout << "enter Email: " << endl; - cin >> newContact->Email; + cin >> newContact[i].Email; cout << "enter Street Address: " << endl; - cin >> newContact->StreetAddress; + cin >> newContact[i].StreetAddress; cout << "enter city: " << endl; - cin >> newContact->City; + cin >> newContact[i].City; cout << "enter State: " << endl; - cin >> newContact->State; + cin >> newContact[i].State; cout << "enter Zip: " << endl; - cin >> newContact->Zip; + cin >> newContact[i].Zip; break; } //cout << newContact[i]->Name << "\n" << newContact[i]->Email << "\n" << newContact[i]->StreetAddress << "\n" << newContact[i]->City << "\n" << newContact[i]->State << "\n" << newContact[i]->Zip << endl; @@ -62,35 +60,39 @@ char addNew(contact* newContact, size_t MAX) // state // zip -void update(struct contact* newContact, size_t MAX) +void update(struct contact newContact[], size_t MAX) { + cout << "select a contact to delete" << endl; int i = 0; int c = 0; cin >> i; i = i - 1; - newContact->id; - cin >> c; - if (c == 1) - { - cout << "enter name: " << endl; - cin >> newContact->Name; - cout << "enter Email: " << endl; - cin >> newContact->Email; - cout << "enter Street Address: " << endl; - cin >> newContact->StreetAddress; - cout << "enter city: " << endl; - cin >> newContact->City; - cout << "enter State: " << endl; - cin >> newContact->State; - cout << "enter Zip: " << endl; - cin >> newContact->Zip; + if (i == newContact[i].id) { + cin >> c; + if (c == 1) + { + cout << "enter name: " << endl; + cin >> newContact[i].Name; + cout << "enter Email: " << endl; + cin >> newContact[i].Email; + cout << "enter Street Address: " << endl; + cin >> newContact[i].StreetAddress; + cout << "enter city: " << endl; + cin >> newContact[i].City; + cout << "enter State: " << endl; + cin >> newContact[i].State; + cout << "enter Zip: " << endl; + cin >> newContact[i].Zip; + } } + } void printAll(contact newContact, size_t MAX) { for (int i = 0; i < MAX; ++i) { + cout << newContact.id << endl; cout << "name: " << newContact.Name << endl; cout << "Email: " << newContact.Email << endl; cout << "Address: " << newContact.StreetAddress << endl; diff --git a/Project1/program.cpp b/Project1/program.cpp index 135546c..390bb30 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -27,28 +27,28 @@ int main() { constexpr size_t MAX = 10; int O = 1; - contact newContact; + contact newContact[MAX]; while (O == 1) { int c = 0; - cout << "1. Enter a name\n"; - cout << "2. Delete a name\n"; - cout << "3. List the file\n"; + cout << "1. Enter a contact\n"; + cout << "2. Update a contact\n"; + cout << "3. print all contacts\n"; cout << "4. Quit\n"; - cout << "\nEnter your choice: "; + cout << "\nEnter your choice: " << endl; cin >> c; //c = menu(); if (c == 1) { - addNew(&newContact, MAX); + addNew(newContact[], MAX); } if (c == 2) { - update(&newContact, MAX); + update(newContact[], MAX); } if (c == 3) { - printAll(newContact, MAX); + printAll(newContact[], MAX); } if (c == 4) { |