aboutsummaryrefslogtreecommitdiff
path: root/Homework7/Homework7/ContactList.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Homework7/Homework7/ContactList.cpp')
-rw-r--r--Homework7/Homework7/ContactList.cpp81
1 files changed, 77 insertions, 4 deletions
diff --git a/Homework7/Homework7/ContactList.cpp b/Homework7/Homework7/ContactList.cpp
index f255ffb..c5314f4 100644
--- a/Homework7/Homework7/ContactList.cpp
+++ b/Homework7/Homework7/ContactList.cpp
@@ -1,4 +1,5 @@
#include "ContactList.h"
+#include "MenuHelper.h"
Contact* ContactList::AllocateContactList(const size_t& size)
{
Contact* contacts = nullptr;
@@ -16,6 +17,55 @@ ContactList::ContactList(const size_t& size)
contacts_ = AllocateContactList(size);
}
+ContactList& ContactList::operator=(const ContactList& rhs)
+{
+ if (rhs.contacts_ != nullptr)
+ {
+ contacts_ = AllocateContactList(sizeof(rhs.contacts_));
+
+ for (auto i = 0u; i < length_; i++)
+ {
+ contacts_[i] = rhs.contacts_[i];
+ }
+
+ size_++;
+ }
+ else
+ {
+ contacts_ = nullptr;
+ }
+
+ return *this;
+}
+ContactList::ContactList(ContactList&& move)
+{
+ *this = move;
+}
+ContactList& ContactList::operator=(ContactList&& rhs)
+{
+ if (this != &rhs)
+ {
+ contacts_ = AllocateContactList(sizeof(rhs.contacts_));
+
+ for (auto i = 0u; i < length_; i++)
+ {
+ contacts_[i] = rhs.contacts_[i];
+ }
+
+ size_++;
+ }
+ else
+ {
+ contacts_ = nullptr;
+ }
+
+ return *this;
+
+}
+ContactList::ContactList(const ContactList& copy)
+{
+ *this = copy;
+}
ContactList::~ContactList()
{
delete[] contacts_;
@@ -24,11 +74,34 @@ ContactList::~ContactList()
void ContactList::DeleteContact(Contact& contact)
{
+ Prompts("Which contact would you like to delete?");
+ int i = 0;
+ std::cin >> i;
+ Contact empty(contact);
+ empty.SetFirstName(" ");
+ empty.SetLastName(" ");
+ empty.SetEmail(" ");
+ empty.SetStreetAddress(" ");
+ empty.SetState(" ");
+ empty.SetCity(" ");
+ empty.SetZip(NULL);
+
+ contact = empty;
+
+ contacts_[i] = empty;
+
}
-void ContactList::CopyList(const Contact* contacts, const size_t& size)
+void ContactList::CopyList(const Contact* contacts, const size_t& length)
{
+ length_ = length; //new overall length
+ contacts_ = AllocateContactList(length);
+
+ for (auto i = 0u; i < length; i++)
+ {
+ contacts_[i] = contacts[i];
+ }
}
@@ -41,13 +114,13 @@ void ContactList::PrintList() const
{
for (auto i = 0u; i < size_; i++)
{
- contacts_[i].Print();
+ std::cout << i << ": "; contacts_[i].Print();
+ std::cout << std::endl;
}
}
size_t ContactList::Size() const
{
- return size_t();
+ return size_;
}
-