diff options
| author | Connor McDowell <[email protected]> | 2024-03-09 18:41:38 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-09 18:41:38 -0800 |
| commit | 9a9e4428f4c17936ae9c22bf58e64a437ac93fe7 (patch) | |
| tree | f613239c3b639b3412df71c34735e9430fe561fe | |
| parent | small cleanup (diff) | |
| download | homework-7-connormcdowell275-main.tar.xz homework-7-connormcdowell275-main.zip | |
copy works as intended
print works as intended
| -rw-r--r-- | Project1/Contact_list.h | 2 | ||||
| -rw-r--r-- | Project1/Contacts.h | 2 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 49 |
3 files changed, 25 insertions, 28 deletions
diff --git a/Project1/Contact_list.h b/Project1/Contact_list.h index 9748cee..3f22752 100644 --- a/Project1/Contact_list.h +++ b/Project1/Contact_list.h @@ -21,7 +21,7 @@ public: contact_list() = default; contact_list(const size_t& size); ~contact_list(); - void CopyList(const contact* contacts, const size_t& size); + void CopyList(contact* contacts, size_t size); void set_length(size_t MAX); size_t get_length(); diff --git a/Project1/Contacts.h b/Project1/Contacts.h index d488a43..82a7446 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -12,7 +12,7 @@ public: // constructors and destructors. contact() = default; - contact& operator=(const contact& rhs); + contact& operator=(contact& rhs); contact(contact&& move) noexcept; contact& operator=(contact&& rhs) noexcept; diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index 8c09924..d9f6cf7 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -27,7 +27,7 @@ contact* contact_list::allocateContactList(const size_t& size) length_ = size; - contacts_ = new contact[size]; + contacts_ = new contact[size]{}; return contacts_; } @@ -41,19 +41,26 @@ contact_list::contact_list(const size_t& size) //standard functions for contact and contact_list classes //copy (contact_list) -void contact_list::CopyList(const contact* contacts, const size_t& size) +void contact_list::CopyList(contact* contacts,size_t size) { length_ = size; - contacts_ = allocateContactList(size); + //contacts_ = allocateContactList(size); + contact* newContacts = new contact[size]; for (auto i = 0u; i < size; ++i) { - contacts_[i] = contacts[i]; + newContacts[i] = contacts_[i]; } cout << "Class copied!" << endl; + cout << "printing!" << endl; + for (auto i = 0u; i < size; i++) + { + cout << "Contact number: " << i << endl; + newContacts[i].print(); + } } //copy operator (contact) -contact& contact::operator=(const contact& rhs) +contact& contact::operator=(contact& rhs) { if (this != &rhs) { @@ -193,7 +200,7 @@ size_t contact::Get_id() void contact::print() { - cout << "Contact number: " << _id << endl; + //cout << "Contact number: " << _id << endl; cout << "Full name: " << _firstName << " " << _lastName << endl; cout << "Street Address: " << _streetAddress << endl; cout << "City: " << _city << endl; @@ -298,7 +305,7 @@ void contact_list::AddContact(contact contact[], size_t& t, contact_struct save) for (size_t i = t; i < size_;) { contacts_[i].Set_a(0); - contacts_[i].Set_id(i); + contacts_[i].Set_id(i + 1); //newContact[i].count = t; cin.ignore(1000, '\n'); cout << "Please enter each piece of information when you are prompted to" << endl; @@ -388,13 +395,13 @@ void contact_list::Print() const size_t check = contacts_[i].Get_a(); - /*if (contacts_[i].Get_id() == check) + if (check == 1) { i = i + 1; } if (contacts_[i].Get_id() == 0) { break; - }*/ + } if (contacts_[i].Get_id() < 0) { break; } @@ -471,32 +478,21 @@ void contact_list::DeleteContact(contact* contact[]) cout << "The list of contacts and their names will now print" << endl; for (auto i = 0u; i < size_; i++) { - if (contacts_[i].Get_id() == 0) { + /* if (contacts_[i].Get_id() == 0) { break; - } + }*/ if (contacts_[i].Get_id() < 0) { break; } if (contacts_[i].Get_id() > size_) { break; } - //if (newContact[i].a == 1) - //{ - // break; - //} - 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'); - cout << "Enter the id number of the contact you'd like to delete" << endl; - cin >> delete_choice; - if (delete_choice == contacts_[i].Get_id()) + if (contacts_[i].Get_a() == 1) { - contacts_[i].Set_a(1); - cout << "Contact number: " << contacts_[i].Get_id() << " deleted" << endl; - contacts_[i + 1].Set_id(contacts_[i + 1].Get_id() - 1); break; } + + cout << "Id number: " << contacts_[i].Get_id() << " is under the name: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << endl; } for (auto i = 0u; i < size_; i++) { @@ -512,7 +508,8 @@ void contact_list::DeleteContact(contact* contact[]) if (delete_choice == contacts_[i].Get_id()) { contacts_[i].Set_a(1); - contacts_[i + 1].Set_id(i - 1); + contacts_[i + 1].Set_id(i); + cout << "the contact for: " << contacts_[i].Get_firstName() << " " << contacts_[i].Get_lastName() << " (id number: " << contacts_[i].Get_id() << "Has been deleted. (bool check = " << contacts_[i].Get_a() << endl; break; } } |