aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--InClassExercise14/InClassExercise14/Contacts.cpp36
-rw-r--r--InClassExercise14/InClassExercise14/Contacts.h13
-rw-r--r--InClassExercise14/InClassExercise14/main.cpp19
3 files changed, 63 insertions, 5 deletions
diff --git a/InClassExercise14/InClassExercise14/Contacts.cpp b/InClassExercise14/InClassExercise14/Contacts.cpp
index 87ff30b..d37054d 100644
--- a/InClassExercise14/InClassExercise14/Contacts.cpp
+++ b/InClassExercise14/InClassExercise14/Contacts.cpp
@@ -17,8 +17,44 @@ Contact::Contact(const char* firstName, const char* lastName, const char* street
Contact::~Contact() { }
+//Copy Constructor
+Contact::Contact(const Contact& copy) {
+ *this = copy;
+}
+
+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;
+}
+Contact& Contact::operator=(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;
+}
+
+
+
+Contact::Contact(Contact&& move) {
+ *this = std::move(move);
+}
+
void Contact::Print() {
std::cout << "First Name: " << _firstName << std::endl;
std::cout << "Last Name: " << _lastName << std::endl;
diff --git a/InClassExercise14/InClassExercise14/Contacts.h b/InClassExercise14/InClassExercise14/Contacts.h
index 0749548..08a7c80 100644
--- a/InClassExercise14/InClassExercise14/Contacts.h
+++ b/InClassExercise14/InClassExercise14/Contacts.h
@@ -5,13 +5,21 @@ class Contact {
public:
Contact();
Contact(const char* firstName, const char* lastName, const char* streetAddress, const char* city, const char* state, int zip, const char* email);
+
+
+ Contact(const Contact& copy);
+ Contact& operator=(const Contact& rhs);
+
+
+ Contact(Contact&& move);
+ Contact& operator=(Contact&& rhs);
~Contact();
void Print();
-
+
const char* GetFirstName();
void SetFirstName(const char* firstName);
@@ -37,6 +45,8 @@ public:
void SetEmail(const char* email);
+
+
private:
@@ -49,6 +59,7 @@ private:
int _zip{ 0 };
const char* _email{ };
+
};
diff --git a/InClassExercise14/InClassExercise14/main.cpp b/InClassExercise14/InClassExercise14/main.cpp
index b50b3a7..8411b7a 100644
--- a/InClassExercise14/InClassExercise14/main.cpp
+++ b/InClassExercise14/InClassExercise14/main.cpp
@@ -7,16 +7,18 @@
#include<iostream>
int main() {
+ Contact();
- Contact newContact;
-
- std::cout << newContact.GetFirstName();
+ Contact newContact;
+ std::cout<<newContact.GetFirstName();
+ newContact = newContact;
+
newContact.GetFirstName();
newContact.SetFirstName("Yana");
-
+
newContact.GetLastName();
newContact.SetLastName("Blashchishina");
@@ -38,5 +40,14 @@ int main() {
newContact.Print();
+ Contact anotherContact("Yana, Not Portland");
+ anotherContact.Print();
+
+
+ anotherContact = newContact;
+
+ Contact copyContact(anotherContact);
+ copyContact.Print();
+
return 0;
} \ No newline at end of file