#ifndef CONTACT_HPP #define CONTACT_HPP #include #include #define _CRT_SECURE_NO_WARNINGS using std::strcpy; using std::cout; using std::endl; using std::cin; using std::numeric_limits; using std::streamsize; constexpr size_t MAX_STREAM_SIZE = numeric_limits::max(); namespace MyStructures //variables declared here act as a global variable { class Contact { public: Contact() = default; Contact(char* name, const short age); ~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 const char* GetFirstName(); void SetFirstName(char* firstname); const char* GetLastName(); void SetLastName(char* lastname); const char* GetEmail(); void SetEmail(char* email); const char* GetStreet(); void SetStreet(char* street); const char* GetState(); void SetState(char* state); const char* GetCity(); void SetCity(char* city); int GetZip(); void SetZip(int zip); bool operator != (const Contact & rhs) const; bool operator == (const Contact& rhs) const; void Print() const; private: char* firstname_{ nullptr }; char* lastname_{ nullptr }; char* email_{ nullptr }; char* street_{ nullptr }; char* state_{ nullptr }; char* city_{ nullptr }; int zip_ = { 0 }; }; inline Contact::Contact(char* name, const short age) { firstname_ = name; } inline Contact::Contact(const Contact& copy) :firstname_ (copy.firstname_), lastname_ (copy.lastname_), email_(copy.email_), state_(copy.state_), city_(copy.city_), street_(copy.street_), zip_(copy.zip_) { strcpy(firstname_, copy.firstname_); strcpy(lastname_, copy.lastname_); strcpy(email_, copy.email_); strcpy(street_, copy.street_); strcpy(state_, copy.state_); strcpy(city_, copy.city_); zip_ = copy.zip_; } inline Contact& Contact::operator=(const Contact& rhs) { if (this != &rhs) { firstname_ = rhs.firstname_; lastname_ = rhs.lastname_; email_ = rhs.email_; street_ = rhs.street_; state_ = rhs.state_; city_ = rhs.city_; zip_ = rhs.zip_; } return *this; } inline Contact::Contact(Contact&& move) { *this = std::move(move); } inline Contact& Contact::operator=(Contact&& rhs) { if (this != &rhs) { firstname_ = rhs.firstname_; lastname_ = rhs.lastname_; email_ = rhs.email_; street_ = rhs.street_; state_ = rhs.state_; city_ = rhs.city_; zip_ = rhs.zip_; } return *this; } inline const char* Contact::GetFirstName() { return firstname_; } void Contact::SetFirstName(char* firstname) { firstname_ = firstname; } inline const char* Contact::GetLastName() { return lastname_; } inline void Contact::SetLastName(char* lastname) { lastname_ = lastname; } inline const char* Contact::GetEmail() { return email_; } inline void Contact::SetEmail(char* email) { email_ = email; } inline const char* Contact::GetStreet() { return street_; } inline void Contact::SetStreet(char* street) { street_ = street; } inline const char* Contact::GetState() { return state_; } inline void Contact::SetState(char* state) { state_ = state; } inline const char* Contact::GetCity() { return city_; } inline void Contact::SetCity(char* city) { city_ = city; } inline int Contact::GetZip() { return zip_; } inline void Contact::SetZip(int zip) { zip_ = zip; } inline bool Contact::operator!=(const Contact& rhs) const { if (std::strcmp(firstname_, rhs.firstname_) != 0) { return true; } if (std::strcmp(lastname_, rhs.lastname_) != 0) { return true; } if (std::strcmp(email_, rhs.email_) != 0) { return true; } if (std::strcmp(street_, rhs.street_) != 0) { return true; } if (std::strcmp(state_, rhs.state_) != 0) { return true; } if (std::strcmp(city_, rhs.city_) != 0) { return true; } if (zip_ != rhs.zip_) { return true; } return false; } inline bool Contact::operator==(const Contact& rhs) const { if (std::strcmp(firstname_, rhs.firstname_) != 0) { return false; } if (std::strcmp(lastname_, rhs.lastname_) != 0) { return false; } if (std::strcmp(email_, rhs.email_) != 0) { return false; } if (std::strcmp(street_, rhs.street_) != 0) { return false; } if (std::strcmp(state_, rhs.state_) != 0) { return false; } if (std::strcmp(city_, rhs.city_) != 0) { return false; } if (zip_ != rhs.zip_) { return false; } return true; } void Contact::Print() const { std::cout << "Name: " << firstname_ << " " << lastname_ << std::endl; std::cout << "Email: " << email_ << std::endl; std::cout << "Street Address: " << street_ << std::endl; std::cout << "State: " << state_ << std::endl; std::cout << "City: " << city_ << std::endl; std::cout << "Zip Code: " << zip_ << std::endl; std::cout << std::endl; } } #endif