aboutsummaryrefslogtreecommitdiff
path: root/Project1/contacts.cpp
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-03-08 12:58:49 -0800
committerConnor McDowell <[email protected]>2024-03-08 12:58:49 -0800
commit18b408df7017403aff427b62146cea6323dce3d3 (patch)
treeebad0359d711dbd0e254c146b849a54f1c882182 /Project1/contacts.cpp
parentrefactored with strings instead of char arrays (diff)
downloadarchived-homework-7-connormcdowell275-18b408df7017403aff427b62146cea6323dce3d3.tar.xz
archived-homework-7-connormcdowell275-18b408df7017403aff427b62146cea6323dce3d3.zip
alrighty! it should be done! i think all 4 standard functions are there so its should have everything!
Diffstat (limited to 'Project1/contacts.cpp')
-rw-r--r--Project1/contacts.cpp161
1 files changed, 106 insertions, 55 deletions
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];
- }
-}
+