diff options
| author | rPatrickWarner <[email protected]> | 2024-02-26 13:19:03 -0800 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-02-26 13:19:03 -0800 |
| commit | 83d973e764ff7d4454879c69e88364da27865a84 (patch) | |
| tree | 6978ba339df208f94a8110a993ef814732e5ba98 | |
| parent | more changes (diff) | |
| download | homework-7-reecepwarner-83d973e764ff7d4454879c69e88364da27865a84.tar.xz homework-7-reecepwarner-83d973e764ff7d4454879c69e88364da27865a84.zip | |
all standard functions and delete
| -rw-r--r-- | Homework7/Homework7/Contact.cpp | 51 | ||||
| -rw-r--r-- | Homework7/Homework7/Contact.h | 11 | ||||
| -rw-r--r-- | Homework7/Homework7/ContactList.cpp | 81 | ||||
| -rw-r--r-- | Homework7/Homework7/ContactList.h | 22 | ||||
| -rw-r--r-- | Homework7/Homework7/Homework7.vcxproj | 2 | ||||
| -rw-r--r-- | Homework7/Homework7/Homework7.vcxproj.filters | 6 | ||||
| -rw-r--r-- | Homework7/Homework7/Menu.cpp | 97 | ||||
| -rw-r--r-- | Homework7/Homework7/MenuHelper.h | 15 | ||||
| -rw-r--r-- | Homework7/Homework7/main.cpp | 39 |
9 files changed, 283 insertions, 41 deletions
diff --git a/Homework7/Homework7/Contact.cpp b/Homework7/Homework7/Contact.cpp index 0140a66..bf097fb 100644 --- a/Homework7/Homework7/Contact.cpp +++ b/Homework7/Homework7/Contact.cpp @@ -1,4 +1,7 @@ -#include "Contact.h" + +#include "MenuHelper.h" +#include <string> +#include <vector> Contact::Contact(const Contact& copy)//Copy Constructor @@ -48,12 +51,23 @@ Contact::Contact(Contact&& move) //Move Constructor } +void Contact::SetFirstName(const char* firstname) +{ + _firstname = firstname; +} + +const char* Contact::GetFirstName() +{ + return _firstname; +} void Contact::SetLastName(const char* lastname) { + _lastname = lastname; + } const char* Contact::GetLastName() @@ -74,7 +88,7 @@ const char* Contact::GetStreetAddress() void Contact::SetCity(const char* city) { - _city = city; + _city = city; } const char* Contact::GetCity() { @@ -108,23 +122,36 @@ const char* Contact::GetEmail() return _email; } -void Contact::Print() + +int Contact::InputInt() +{ + int data; + std::cin >> data; + return data; +} + + +char* Contact::InputNonInt(char* PH) +{ + + /*std::cin.get(PH, 100, '\n'); + std::cin.ignore();*/ + std::cin >> PH; + + return PH; +} + + +void Contact::Print() const { + std::cout << "Name: " << _firstname << " " << _lastname<< std::endl; std::cout << "Email: " << _email << std::endl; std::cout << "Street Address: " << _streetaddress << std::endl; std::cout << "City: " << _city << std::endl; std::cout << "State: " << _state << std::endl; std::cout << "ZipCode: " << _zip << std::endl; + std::cout << "////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"; } -void Contact::SetFirstName(const char* firstname) -{ - _firstname = firstname; -} - -const char* Contact::GetFirstName() -{ - return _firstname; -}
\ No newline at end of file diff --git a/Homework7/Homework7/Contact.h b/Homework7/Homework7/Contact.h index 009be09..bf95ebc 100644 --- a/Homework7/Homework7/Contact.h +++ b/Homework7/Homework7/Contact.h @@ -38,7 +38,13 @@ public: void SetEmail(const char* email); const char* GetEmail(); - void Print(); + + int InputInt(); + + char* InputNonInt(char* PH); + void Print() const; + + private: const char* _firstname{ }; @@ -46,8 +52,9 @@ private: const char* _streetaddress{ }; const char* _city{ }; const char* _state{}; - int _zip = 0; const char* _email{ }; + int _zip = 0; + }; 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_; } - diff --git a/Homework7/Homework7/ContactList.h b/Homework7/Homework7/ContactList.h index 6a3a6e9..e195970 100644 --- a/Homework7/Homework7/ContactList.h +++ b/Homework7/Homework7/ContactList.h @@ -4,25 +4,31 @@ 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(const ContactList& copy);//CopyConstructor + ContactList& operator=(const ContactList& rhs);//CopyAssignment + ContactList(ContactList&& move);//MoveConstructor + ContactList& operator=(ContactList&& rhs);//MoveAssignment + ~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 CopyList(const Contact* contacts, const size_t& length); //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 +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 + }; diff --git a/Homework7/Homework7/Homework7.vcxproj b/Homework7/Homework7/Homework7.vcxproj index d101387..23610b4 100644 --- a/Homework7/Homework7/Homework7.vcxproj +++ b/Homework7/Homework7/Homework7.vcxproj @@ -130,10 +130,12 @@ <ClCompile Include="Contact.cpp" /> <ClCompile Include="ContactList.cpp" /> <ClCompile Include="main.cpp" /> + <ClCompile Include="Menu.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="Contact.h" /> <ClInclude Include="ContactList.h" /> + <ClInclude Include="MenuHelper.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 4a3c89a..23cdde0 100644 --- a/Homework7/Homework7/Homework7.vcxproj.filters +++ b/Homework7/Homework7/Homework7.vcxproj.filters @@ -24,6 +24,9 @@ <ClCompile Include="ContactList.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="Menu.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="Contact.h"> @@ -32,5 +35,8 @@ <ClInclude Include="ContactList.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="MenuHelper.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Homework7/Homework7/Menu.cpp b/Homework7/Homework7/Menu.cpp new file mode 100644 index 0000000..dbb2abb --- /dev/null +++ b/Homework7/Homework7/Menu.cpp @@ -0,0 +1,97 @@ +#include "MenuHelper.h" +#include "ContactList.h" + +Contact newContact; +Contact nextContact; + +ContactList contacts(3); +void Prompts(const char* prompt) +{ + std::cout << prompt << std::endl; +} +void Menu() +{ + char Options = '\0'; + + do + { + std::cout << "Welcome to the contacts menu\n" + << "1)Add New Contact\n" + << "2)Update Contact\n" + << "3)Print All Contacts\n" + << "4)Delete Contact\n" + << "5)Exit\n"; + std::cin >> Options; + switch (Options) + { + case('1'): + InputContact(); + break; + case('2'): + break; + case('3'): + PrintContact(); + break; + case('4'): + contacts.DeleteContact(newContact); + break; + case('5'): + + break; + default: + std::cout << "Invalid Input, Try Again!" << std::endl; + } + + } while (Options != '5'); + +} + + + +ContactList ContactAdder() +{ + ContactList contacts(3); + return contacts; +} + +void ContactAddition() +{ + + +} +void InputContact() +{ + + + newContact.SetFirstName("Reece"); + newContact.SetLastName("Warner"); + newContact.SetEmail("[email protected]"); + newContact.SetStreetAddress("SW Ashland Loop"); + newContact.SetCity("Medford"); + newContact.SetState("Oregon"); + newContact.SetZip(97501); + + nextContact.SetFirstName("Jim"); + nextContact.SetLastName("Belushi"); + nextContact.SetEmail("[email protected]"); + nextContact.SetStreetAddress("Belushi Farms"); + nextContact.SetCity("Central Point"); + nextContact.SetState("Oregon"); + nextContact.SetZip(97504); + + + + contacts.AddContact(newContact); + contacts.AddContact(nextContact); + +} + + + + +void PrintContact() +{ + + contacts.PrintList(); + +} diff --git a/Homework7/Homework7/MenuHelper.h b/Homework7/Homework7/MenuHelper.h new file mode 100644 index 0000000..33b0b49 --- /dev/null +++ b/Homework7/Homework7/MenuHelper.h @@ -0,0 +1,15 @@ +#ifndef MENU_HELPER_H +#define MENU_HELPER_H +#include "Contact.h" +#include "ContactList.h" + +void Prompts(const char* prompt); +void Menu(); + +void InputContact(); +void PrintContact(); +void ContactAddition(); +ContactList ContactAdder(); + + +#endif diff --git a/Homework7/Homework7/main.cpp b/Homework7/Homework7/main.cpp index 4933f31..7f25651 100644 --- a/Homework7/Homework7/main.cpp +++ b/Homework7/Homework7/main.cpp @@ -5,25 +5,34 @@ #include "Contact.h" #include "ContactList.h" - +#include "MenuHelper.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(); + + Menu(); + + //Contact newContact; + //newContact.SetFirstName("Reece"); + //newContact.SetLastName("Warner"); + //newContact.SetEmail("[email protected]"); + //newContact.SetStreetAddress("SW Ashland Loop"); + //newContact.SetCity("Medford"); + //newContact.SetState("Oregon"); + //newContact.SetZip(97501); + // + // + //ContactList contacts(3); + //contacts.AddContact(newContact); + //contacts.PrintList(); + + //ContactList contaxxxx(3); + //ContactList contaxxxx(contacts); //copy constructor + //contaxxxx = contacts; //copy assignment + //contaxxxx.PrintList(); + //contaxxxx = contacts;//move assignment + //contaxxxx.PrintList(); return 0; }
\ No newline at end of file |