diff options
Diffstat (limited to 'Homework7/Homework7/ContactList.cpp')
| -rw-r--r-- | Homework7/Homework7/ContactList.cpp | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/Homework7/Homework7/ContactList.cpp b/Homework7/Homework7/ContactList.cpp index c85ee80..70d9122 100644 --- a/Homework7/Homework7/ContactList.cpp +++ b/Homework7/Homework7/ContactList.cpp @@ -1,5 +1,7 @@ #include "ContactList.h" #include "MenuHelper.h" + + Contact* ContactList::AllocateContactList(const size_t& size) { Contact* contacts = nullptr; @@ -10,6 +12,7 @@ Contact* ContactList::AllocateContactList(const size_t& size) return contacts; } + ContactList::ContactList(const size_t& size) { length_ = size; @@ -17,6 +20,7 @@ ContactList::ContactList(const size_t& size) contacts_ = AllocateContactList(size); } + ContactList& ContactList::operator=(const ContactList& rhs) { if (rhs.contacts_ != nullptr) @@ -37,10 +41,12 @@ ContactList& ContactList::operator=(const ContactList& rhs) return *this; } + ContactList::ContactList(ContactList&& move) { *this = move; } + ContactList& ContactList::operator=(ContactList&& rhs) { if (this != &rhs) @@ -63,10 +69,12 @@ ContactList& ContactList::operator=(ContactList&& rhs) return *this; } + ContactList::ContactList(const ContactList& copy) { *this = copy; } + ContactList::~ContactList() { delete[] contacts_; @@ -74,19 +82,51 @@ ContactList::~ContactList() } -void ContactList::DeleteContact(Contact& contact) +void ContactList::DeleteContact(const char* prompt, ContactList contacts) { - Contact empty(contact); - empty.SetFirstName(nullptr); - empty.SetLastName(nullptr); - empty.SetEmail(nullptr); - empty.SetStreetAddress(nullptr); - empty.SetState(nullptr); - empty.SetCity(nullptr); - empty.SetZip(NULL); - - contact = empty; - + contacts.PrintList(); + + int i = 0; + std::cout << prompt << std::endl; + + std::cin >> i; + + while (!std::cin || i > size_) + { + + std::cout << prompt << std::endl; + std::cin.clear(); + + cin.ignore(MAX_STREAM_SIZE, '\n'); + std::cin >> i; + + } + + contacts_[i].SetFirstName(nullptr); + contacts_[i].SetLastName(nullptr); + contacts_[i].SetEmail(nullptr); + contacts_[i].SetStreetAddress(nullptr); + contacts_[i].SetState(nullptr); + contacts_[i].SetCity(nullptr); + contacts_[i].SetZip(NULL); + + if (i == 0) //if you're deleting the first contact + { + for (auto j = 0u; j < size_; j++) + { + contacts_[j] = contacts_[j+1]; + } + + } + if (i > 0 && i < size_) //if you're deleting anything in the middle + { + for (i; i < size_; i++) + { + contacts_[i] = contacts_[i + 1]; + } + } + + size_--; //decrement the size of array because of removal } void ContactList::CopyList(const Contact* contacts, const size_t& length) @@ -103,20 +143,22 @@ void ContactList::CopyList(const Contact* contacts, const size_t& length) void ContactList::AddContact(const Contact& contact) { - contacts_[size_++] = contact; //the post increment will add a new contact and keep track of the number of contacts + contacts_[size_++] = contact; } void ContactList::PrintList() const { for (auto i = 0u; i < size_; i++) { - contacts_[i].Print(); + std::cout <<"Contact:" << i; contacts_[i].Print(); std::cout << std::endl; } } size_t ContactList::Size() const { - return size_; } + + + |