diff options
| author | rPatrickWarner <[email protected]> | 2024-02-20 14:30:00 -0800 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-02-20 14:30:00 -0800 |
| commit | 942aa814361e7f98356d30c19eb6c7c3aec7cbc5 (patch) | |
| tree | 2f4089996f6283bdc1301cf1ac13427e2f6bb0be | |
| parent | init (diff) | |
| download | homework-7-reecepwarner-942aa814361e7f98356d30c19eb6c7c3aec7cbc5.tar.xz homework-7-reecepwarner-942aa814361e7f98356d30c19eb6c7c3aec7cbc5.zip | |
more changes
| -rw-r--r-- | Homework7/Homework7/Contact.h | 6 | ||||
| -rw-r--r-- | Homework7/Homework7/ContactList.cpp | 53 | ||||
| -rw-r--r-- | Homework7/Homework7/ContactList.h | 33 | ||||
| -rw-r--r-- | Homework7/Homework7/Homework7.vcxproj | 2 | ||||
| -rw-r--r-- | Homework7/Homework7/Homework7.vcxproj.filters | 6 | ||||
| -rw-r--r-- | Homework7/Homework7/main.cpp | 17 |
6 files changed, 116 insertions, 1 deletions
diff --git a/Homework7/Homework7/Contact.h b/Homework7/Homework7/Contact.h index 72c0979..009be09 100644 --- a/Homework7/Homework7/Contact.h +++ b/Homework7/Homework7/Contact.h @@ -51,4 +51,10 @@ private: }; + + + + + + #endif diff --git a/Homework7/Homework7/ContactList.cpp b/Homework7/Homework7/ContactList.cpp new file mode 100644 index 0000000..f255ffb --- /dev/null +++ b/Homework7/Homework7/ContactList.cpp @@ -0,0 +1,53 @@ +#include "ContactList.h" +Contact* ContactList::AllocateContactList(const size_t& size) +{ + Contact* contacts = nullptr; + + length_ = size; + + contacts = new Contact[size]; + + return contacts; +} +ContactList::ContactList(const size_t& size) +{ + length_ = size; + + contacts_ = AllocateContactList(size); + +} +ContactList::~ContactList() +{ + delete[] contacts_; + contacts_ = nullptr; +} + +void ContactList::DeleteContact(Contact& contact) +{ + +} + +void ContactList::CopyList(const Contact* contacts, const size_t& size) +{ + +} + +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 +} + +void ContactList::PrintList() const +{ + for (auto i = 0u; i < size_; i++) + { + contacts_[i].Print(); + } +} + +size_t ContactList::Size() const +{ + + return size_t(); +} + diff --git a/Homework7/Homework7/ContactList.h b/Homework7/Homework7/ContactList.h new file mode 100644 index 0000000..6a3a6e9 --- /dev/null +++ b/Homework7/Homework7/ContactList.h @@ -0,0 +1,33 @@ +#ifndef CONTACT_LIST_H +#define CONTACT_LIST_H +#include "Contact.h" + +class ContactList +{ +private: + Contact* contacts_{ nullptr }; + + size_t length_{ 0 }; //total length of array + size_t size_{ 0 }; //total used elements in array + + Contact* AllocateContactList(const size_t& size); //This is private because you don't want someone to have access to memory. No access outside of the class + +public: + ContactList() = default; + ContactList(const size_t& size); + ~ContactList(); + + void DeleteContact(Contact& contact); + void CopyList(const Contact* contacts, const size_t& size); //constant reference beccause you dont want to change the value + void AddContact(const Contact& contact); + void PrintList() const; //const means that it will never change the data + size_t Size() const; //const function + +}; + + + + + + +#endif diff --git a/Homework7/Homework7/Homework7.vcxproj b/Homework7/Homework7/Homework7.vcxproj index c22ebd2..d101387 100644 --- a/Homework7/Homework7/Homework7.vcxproj +++ b/Homework7/Homework7/Homework7.vcxproj @@ -128,10 +128,12 @@ </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="Contact.cpp" /> + <ClCompile Include="ContactList.cpp" /> <ClCompile Include="main.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="Contact.h" /> + <ClInclude Include="ContactList.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/Homework7/Homework7/Homework7.vcxproj.filters b/Homework7/Homework7/Homework7.vcxproj.filters index 7e54a1a..4a3c89a 100644 --- a/Homework7/Homework7/Homework7.vcxproj.filters +++ b/Homework7/Homework7/Homework7.vcxproj.filters @@ -21,10 +21,16 @@ <ClCompile Include="main.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="ContactList.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="Contact.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="ContactList.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Homework7/Homework7/main.cpp b/Homework7/Homework7/main.cpp index 91beac5..4933f31 100644 --- a/Homework7/Homework7/main.cpp +++ b/Homework7/Homework7/main.cpp @@ -4,11 +4,26 @@ //Homework7AddressBookProgram #include "Contact.h" +#include "ContactList.h" + int main() -{ +{ + Contact newContact; + newContact.SetFirstName("Reece"); + newContact.SetLastName("Warner"); + newContact.SetEmail("[email protected]"); + newContact.SetStreetAddress("28685 SW Ashland Loop"); + newContact.SetCity("Wilsonville"); + newContact.SetState("OR"); + newContact.SetZip(97070); + + + ContactList contacts(3); + contacts.AddContact(newContact); + contacts.PrintList(); return 0; }
\ No newline at end of file |