diff options
Diffstat (limited to 'Homework7/Homework7/ContactList.cpp')
| -rw-r--r-- | Homework7/Homework7/ContactList.cpp | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/Homework7/Homework7/ContactList.cpp b/Homework7/Homework7/ContactList.cpp index 69691b3..b934182 100644 --- a/Homework7/Homework7/ContactList.cpp +++ b/Homework7/Homework7/ContactList.cpp @@ -1,7 +1,69 @@ #include "ContactList.h" -Contact::ContactList() + + +ContactList::ContactList(const size_t& size) +{ + + length_ = size; + contacts_ = AllocateContactList(size); +} + +ContactList::~ContactList() +{ + delete[]contacts_; + contacts_ = nullptr; +} + +void ContactList::DeleteContact(Contact& contact) +{ + for (size_t i = 0; i < length_; ++i) { + if (&contact == &contacts_[i]) { + + delete& contacts_[i]; + + return; + } + } +} + +void ContactList::CopyList(const Contact* contacts, const size_t& length) +{ + length_ = length; + contacts_ = AllocateContactList(length); + + for (auto i = 0u; i < length; ++i) + { + contacts_[i] = contacts[i]; + } +} + +void ContactList::AddContact(const Contact& contact) +{ + contacts_[size_++] = contact; +} + +void ContactList::Print() const +{ + for (auto i = 0u; i < size_; ++i) + { + contacts_[i].Print(); + } +} + +size_t ContactList::GetSize() const +{ + return size_; +} + +Contact* ContactList::AllocateContactList(const size_t& size) { + Contact* contacts = nullptr; + + length_ = size; + + contacts = new Contact[size]; + return contacts; -}
\ No newline at end of file +} |