diff options
| author | rPatrickWarner <[email protected]> | 2024-02-19 21:11:48 -0800 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-02-19 21:11:48 -0800 |
| commit | c5924f3635989aca5ede4c02cc67008e189ef445 (patch) | |
| tree | ec201effcd7b40001a1e8f8e9e3c934a5b7f7303 /InClassExercise14 | |
| parent | init (diff) | |
| download | in-class-exercise-14-reecepwarner-main.tar.xz in-class-exercise-14-reecepwarner-main.zip | |
Diffstat (limited to 'InClassExercise14')
| -rw-r--r-- | InClassExercise14/InClassExercise14/Contact.cpp | 52 | ||||
| -rw-r--r-- | InClassExercise14/InClassExercise14/Contact.h | 24 | ||||
| -rw-r--r-- | InClassExercise14/InClassExercise14/main.cpp | 22 |
3 files changed, 79 insertions, 19 deletions
diff --git a/InClassExercise14/InClassExercise14/Contact.cpp b/InClassExercise14/InClassExercise14/Contact.cpp index f981547..0140a66 100644 --- a/InClassExercise14/InClassExercise14/Contact.cpp +++ b/InClassExercise14/InClassExercise14/Contact.cpp @@ -1,15 +1,55 @@ #include "Contact.h" -Contact::Contact() +Contact::Contact(const Contact& copy)//Copy Constructor +{ + *this = copy; +} + +Contact& Contact::operator=(const Contact& rhs)//Copy Assignment +{ + 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; +} + +Contact& Contact::operator=(Contact&& rhs) //Move Assignment { + 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; } -Contact::~Contact() + +Contact::Contact(Contact&& move) //Move Constructor { + *this = move; } + + void Contact::SetLastName(const char* lastname) { _lastname = lastname; @@ -68,10 +108,6 @@ const char* Contact::GetEmail() return _email; } - - - - void Contact::Print() { std::cout << "Name: " << _firstname << " " << _lastname<< std::endl; @@ -83,12 +119,12 @@ void Contact::Print() } -void Contact::SetFirstName(char* firstname) +void Contact::SetFirstName(const char* firstname) { _firstname = firstname; } -char* Contact::GetFirstName() +const char* Contact::GetFirstName() { return _firstname; }
\ No newline at end of file diff --git a/InClassExercise14/InClassExercise14/Contact.h b/InClassExercise14/InClassExercise14/Contact.h index f5321ba..72c0979 100644 --- a/InClassExercise14/InClassExercise14/Contact.h +++ b/InClassExercise14/InClassExercise14/Contact.h @@ -7,11 +7,15 @@ class Contact { public: - Contact(); + Contact() = default; + + Contact(const Contact& copy); //Copy Constructor + Contact& operator=(const Contact& rhs);//Copy Assignment + Contact(Contact&& move);//Move Constructor + Contact& operator=(Contact&& rhs);//Move Assignment - - ~Contact(); + ~Contact() = default; const char* GetLastName(); void SetLastName(const char* lastname); @@ -37,13 +41,13 @@ public: void Print(); private: - char* _firstname{ }; - char* _lastname{ }; - char* _streetaddress{ }; - char* _city{ }; - char* _state{}; - int _zip; - char* _email{ }; + const char* _firstname{ }; + const char* _lastname{ }; + const char* _streetaddress{ }; + const char* _city{ }; + const char* _state{}; + int _zip = 0; + const char* _email{ }; }; diff --git a/InClassExercise14/InClassExercise14/main.cpp b/InClassExercise14/InClassExercise14/main.cpp index 3dc46a1..f75ba07 100644 --- a/InClassExercise14/InClassExercise14/main.cpp +++ b/InClassExercise14/InClassExercise14/main.cpp @@ -9,10 +9,30 @@ int main() { Contact newContact; - + newContact.SetFirstName("Reece"); + newContact.SetLastName("Warner"); + newContact.SetCity("Wilsonville"); + newContact.SetEmail("[email protected]"); + newContact.SetStreetAddress("28685SWASHLANDLOOP"); + newContact.SetZip(97070); + newContact.SetState("Oregon"); + newContact.Print(); + Contact anotherContact(newContact); + anotherContact.Print(); + + + Contact anotheranotherContact; + anotheranotherContact = newContact; + anotheranotherContact.Print(); + + Contact copyContact(anotherContact); + copyContact.Print(); + + Contact moveContact(anotherContact); + moveContact.Print(); return 0; }
\ No newline at end of file |