diff options
| author | Connor McDowell <[email protected]> | 2024-03-08 12:58:49 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-08 12:58:49 -0800 |
| commit | 18b408df7017403aff427b62146cea6323dce3d3 (patch) | |
| tree | ebad0359d711dbd0e254c146b849a54f1c882182 | |
| parent | refactored with strings instead of char arrays (diff) | |
| download | homework-7-connormcdowell275-18b408df7017403aff427b62146cea6323dce3d3.tar.xz homework-7-connormcdowell275-18b408df7017403aff427b62146cea6323dce3d3.zip | |
alrighty! it should be done! i think all 4 standard functions are there so its should have everything!
| -rw-r--r-- | Project1/Contact_list.h | 7 | ||||
| -rw-r--r-- | Project1/Contacts.h | 6 | ||||
| -rw-r--r-- | Project1/contacts.cpp | 161 | ||||
| -rw-r--r-- | Project1/program.cpp | 3 |
4 files changed, 114 insertions, 63 deletions
diff --git a/Project1/Contact_list.h b/Project1/Contact_list.h index c4c0973..9748cee 100644 --- a/Project1/Contact_list.h +++ b/Project1/Contact_list.h @@ -17,9 +17,11 @@ private: public: + // constructors, destructors and standard functs contact_list() = default; contact_list(const size_t& size); ~contact_list(); + void CopyList(const contact* contacts, const size_t& size); void set_length(size_t MAX); size_t get_length(); @@ -29,13 +31,10 @@ public: void DeleteContact(contact* contact[]); - void CopyList(const contact* contacts, const size_t& size); - - void AddContact(contact contact[], size_t& t, contact_struct save, contact_list contacts); + void AddContact(contact contact[], size_t& t, contact_struct save); void Print() const; - void Update(const contact& contact); }; diff --git a/Project1/Contacts.h b/Project1/Contacts.h index 48a89c3..d488a43 100644 --- a/Project1/Contacts.h +++ b/Project1/Contacts.h @@ -9,13 +9,13 @@ using namespace std; class contact { public: + // constructors and destructors. contact() = default; - /*contact(const contact& copy); contact& operator=(const contact& rhs); - contact(contact&& move); - contact& operator=(contact&& rhs);*/ + contact(contact&& move) noexcept; + contact& operator=(contact&& rhs) noexcept; string Get_firstName(); void Set_firstName(string firstName); diff --git a/Project1/contacts.cpp b/Project1/contacts.cpp index b255def..85bf473 100644 --- a/Project1/contacts.cpp +++ b/Project1/contacts.cpp @@ -9,7 +9,11 @@ using std::cin; using std::cout; using std::endl; -// constructors and destructors +// constructors and destructors for contact + + + +// constructors and destructors for contact_list contact_list::~contact_list() { @@ -34,6 +38,56 @@ contact_list::contact_list(const size_t& size) contacts_ = allocateContactList(size); } +//standard functions for contact and contact_list classes + +//copy (contact_list) +void contact_list::CopyList(const contact* contacts, const size_t& size) +{ + length_ = size; + contacts_ = allocateContactList(size); + + for (auto i = 0u; i < size; ++i) + { + contacts_[i] = contacts[i]; + } +} +//copy operator (contact) +contact& contact::operator=(const contact& rhs) +{ + if (this != &rhs) + { + _firstName = rhs._firstName; + _lastName = rhs._lastName; + _streetAddress = rhs._streetAddress; + _city = rhs._city; + _state = rhs._state; + _zip = rhs._zip; + _email = rhs._email; + } + return *this; +} + +//move (contact) +contact::contact(contact&& move) noexcept +{ + *this = move; + //also *this = std::move(move); +} + +contact& contact::operator=(contact&& rhs) noexcept +{ + if (this != &rhs) + { + _firstName = rhs._firstName; + _lastName = rhs._lastName; + _streetAddress = rhs._streetAddress; + _city = rhs._city; + _state = rhs._state; + _zip = rhs._zip; + _email = rhs._email; + } + return *this; +} //getters n setters @@ -192,7 +246,7 @@ void contact::print() //} //} -void contact_list::AddContact(contact contact[], size_t& t, contact_struct save, contact_list contacts) +void contact_list::AddContact(contact contact[], size_t& t, contact_struct save) { //CURRENTLY TESTING contact_struct _save; @@ -275,6 +329,8 @@ void contact_list::AddContact(contact contact[], size_t& t, contact_struct save, //cout << newContact[i]->Name << "\n" << newContact[i]->Email << "\n" << newContact[i]->StreetAddress << "\n" << newContact[i]->City << "\n" << newContact[i]->State << "\n" << newContact[i]->Zip << endl; } +// not required update function below. + //void contact_list::Update(const contact& contact) //{ // //uses input based on list number from print (though when delete is made will be using that id/name print) to update the values of. @@ -358,50 +414,53 @@ void contact_list::Print() const } } -contact contact_double(contact*& newContact, size_t& MAX, size_t t) -{ - /*hell on earth is in this condenced comment*/ - //supposedly doubles length. doesn't work. - //current ideas: add if loop to whole main with the id counter t and if length of newContact = max double the length. - //current problems: using const size_t max prevents editing size for the whole function, and it resets as soon as the while loop loops or leaves the scope of the if statement. - //contact* doubleContact = new contact[MAX * 2]; - //for (auto a = 0u; a < MAX; ++a) - //{ - // doubleContact[a].a = newContact[a].a; - // doubleContact[a].id = newContact[a].id; - // doubleContact[a].count = newContact[a].count; - // doubleContact[a].Name[25] = newContact[a].Name[25]; - // doubleContact[a].Email[100] = newContact[a].Email[100]; - // doubleContact[a].StreetAddress[35] = newContact[a].StreetAddress[35]; - // doubleContact[a].City[30] = newContact[a].City[30]; - // doubleContact[a].State[3] = newContact[a].State[3]; - // doubleContact[a].Zip = newContact[a].Zip; - // cout << "List number: " << doubleContact[a].id << endl; - // cout << "name: " << doubleContact[a].Name << endl; - // cout << "Email: " << doubleContact[a].Email << endl; - // cout << "Address: " << doubleContact[a].StreetAddress << endl; - // cout << "city: " << doubleContact[a].City << endl; - // cout << "state: " << doubleContact[a].State << endl; - // cout << "Zip: " << doubleContact[a].Zip << endl; - //} - //newContact = doubleContact; - //delete[] doubleContact; - ////delete[] newContact; - //MAX = MAX * 2; - ////printAll(&doubleContact[MAX], MAX); - ////printAll(&newContact[MAX], MAX); - //return newContact[MAX]; - - contact* doubleContact = new contact[MAX * 2]; - for (auto a = 0u; a < MAX; ++a) - { - doubleContact[a] = newContact[a]; - } - delete[] newContact; - newContact = doubleContact; - MAX = MAX * 2; - return newContact[MAX - 1]; -} +// depreciated contact double function below. + +//contact contact_double(contact*& newContact, size_t& MAX, size_t t) +//{ +// /*hell on earth is in this condenced comment*/ +// //supposedly doubles length. doesn't work. +// //current ideas: add if loop to whole main with the id counter t and if length of newContact = max double the length. +// //current problems: using const size_t max prevents editing size for the whole function, and it resets as soon as the while loop loops or leaves the scope of the if statement. +// //contact* doubleContact = new contact[MAX * 2]; +// //for (auto a = 0u; a < MAX; ++a) +// //{ +// // doubleContact[a].a = newContact[a].a; +// // doubleContact[a].id = newContact[a].id; +// // doubleContact[a].count = newContact[a].count; +// // doubleContact[a].Name[25] = newContact[a].Name[25]; +// // doubleContact[a].Email[100] = newContact[a].Email[100]; +// // doubleContact[a].StreetAddress[35] = newContact[a].StreetAddress[35]; +// // doubleContact[a].City[30] = newContact[a].City[30]; +// // doubleContact[a].State[3] = newContact[a].State[3]; +// // doubleContact[a].Zip = newContact[a].Zip; +// // cout << "List number: " << doubleContact[a].id << endl; +// // cout << "name: " << doubleContact[a].Name << endl; +// // cout << "Email: " << doubleContact[a].Email << endl; +// // cout << "Address: " << doubleContact[a].StreetAddress << endl; +// // cout << "city: " << doubleContact[a].City << endl; +// // cout << "state: " << doubleContact[a].State << endl; +// // cout << "Zip: " << doubleContact[a].Zip << endl; +// //} +// //newContact = doubleContact; +// //delete[] doubleContact; +// ////delete[] newContact; +// //MAX = MAX * 2; +// ////printAll(&doubleContact[MAX], MAX); +// ////printAll(&newContact[MAX], MAX); +// //return newContact[MAX]; +// +// //contact* doubleContact = new contact[MAX * 2]; +// //for (auto a = 0u; a < MAX; ++a) +// //{ +// // doubleContact[a] = newContact[a]; +// //} +// //delete[] newContact; +// //newContact = doubleContact; +// //MAX = MAX * 2; +// //return newContact[MAX - 1]; +// return; +//} void contact_list::DeleteContact(contact* contact[]) { @@ -458,15 +517,7 @@ void contact_list::DeleteContact(contact* contact[]) } } -void contact_list::CopyList(const contact* contacts, const size_t& size) -{ - length_ = size; - contacts_ = allocateContactList(size); - for(auto i = 0u; i < size; ++i) - { - contacts_[i] = contacts[i]; - } -} + diff --git a/Project1/program.cpp b/Project1/program.cpp index 4d4d6f6..e9290d9 100644 --- a/Project1/program.cpp +++ b/Project1/program.cpp @@ -44,7 +44,7 @@ int main() { case 1: //addNew(newContact, MAX, t); - contacts.AddContact(newContact, t, save_contacts, contacts); + contacts.AddContact(newContact, t, save_contacts); //addContact(newContact, contacts.get_size(), contacts[MAX]); //for (auto i = 0u; i < MAX; ++i) //{ @@ -104,6 +104,7 @@ int main() //contacts.CopyList(&newContact, MAX); break; case 5: + contacts.~contact_list(); O = 0; break; default: |