diff options
| author | Connor McDowell <[email protected]> | 2024-03-03 15:53:38 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-03 15:53:38 -0800 |
| commit | 76049bedfa0e1dbcc8855776e84c080111cf2d0e (patch) | |
| tree | dfa7766460149eb9677a33cd4caefcf2aab85c8c /Project1 | |
| parent | add new mostly working, will need to tweek counter variable to work with classes (diff) | |
| download | homework-7-connormcdowell275-76049bedfa0e1dbcc8855776e84c080111cf2d0e.tar.xz homework-7-connormcdowell275-76049bedfa0e1dbcc8855776e84c080111cf2d0e.zip | |
delete refactored
Diffstat (limited to 'Project1')
| -rw-r--r-- | Project1/contacts.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 2d800e0..4cbdd2d 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -145,6 +145,7 @@ size_t contact::Get_id() void contact::print() { + cout << "Contact number: " << _id << endl; cout << "Full name: " << _firstName << " " << _lastName << endl; cout << "Street Address: " << _streetAddress << endl; cout << "City: " << _city << endl; @@ -361,28 +362,28 @@ size_t max_double(size_t MAX) return MAX; } -void contact_list::DeleteContact(contact newContact[], size_t MAX) +void contact_list::DeleteContact(contact& contact) { //Work in progress, add BOOL (true) to struct, when this is selected print id list with respective names //then take input of id list number and set bool to false //add to new part to addNew: if bool != 0 then copy and paste update code w/addNew couts cout << "The list of contacts and their names will now print" << endl; - for (auto i = 0u; i < MAX; i++) + for (auto i = 0u; i < size_; i++) { - if (newContact[i].Get_id() == 0) { + if (contacts_[i].Get_id() == 0) { break; } - if (newContact[i].Get_id() < 0) { + if (contacts_[i].Get_id() < 0) { break; } - if (newContact[i].Get_id() > MAX) { + if (contacts_[i].Get_id() > size_) { break; } //if (newContact[i].a == 1) //{ // break; //} - cout << "Id number: " << newContact[i].Get_id() << " is under the name: " << newContact[i].Get_firstName() << " " << newContact[i].Get_lastName() << endl; + cout << "Id number: " << contacts_[i].Get_id() << " is under the name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl; //size_t delete_choice = 0; //cout << "\n"; //cin.ignore(1000, '\n'); @@ -396,22 +397,21 @@ void contact_list::DeleteContact(contact newContact[], size_t MAX) // break; //} } - for (auto i = 0u; i < MAX; i++) + for (auto i = 0u; i < size_; i++) { size_t delete_choice = 0; cout << "\n"; cin.ignore(1000, '\n'); cout << "Enter the id number of the contact you'd like to delete" << endl; cin >> delete_choice; - if (delete_choice != newContact[i].Get_id()) + if (delete_choice != contacts_[i].Get_id()) { i = i + 1; } - if (delete_choice == newContact[i].Get_id()) + if (delete_choice == contacts_[i].Get_id()) { - newContact[i].Set_a(1); - cout << "Contact number: " << newContact[i].Get_id() << " deleted" << endl; - newContact[i + 1].Set_id(i - 1); + contacts_[i].Set_a(1); + contacts_[i + 1].Set_id(i - 1); break; } } |