aboutsummaryrefslogtreecommitdiff
path: root/Homework8/MyStructures/Contact.hpp
diff options
context:
space:
mode:
authorrPatrickWarner <[email protected]>2024-03-04 17:11:54 -0800
committerrPatrickWarner <[email protected]>2024-03-04 17:11:54 -0800
commite5eb6f396d9d7a959c45abf34a095a57b2295a24 (patch)
treecd09a47418711839b533b90299f1b5cf11eb8e0f /Homework8/MyStructures/Contact.hpp
parentinit (diff)
downloadhomework-8-reecepwarner-e5eb6f396d9d7a959c45abf34a095a57b2295a24.tar.xz
homework-8-reecepwarner-e5eb6f396d9d7a959c45abf34a095a57b2295a24.zip
changes
Diffstat (limited to 'Homework8/MyStructures/Contact.hpp')
-rw-r--r--Homework8/MyStructures/Contact.hpp288
1 files changed, 240 insertions, 48 deletions
diff --git a/Homework8/MyStructures/Contact.hpp b/Homework8/MyStructures/Contact.hpp
index f7fda6c..ac480be 100644
--- a/Homework8/MyStructures/Contact.hpp
+++ b/Homework8/MyStructures/Contact.hpp
@@ -1,108 +1,300 @@
#ifndef CONTACT_HPP
#define CONTACT_HPP
+#include <iostream>
+#include <cstring>
+#define _CRT_SECURE_NO_WARNINGS
-namespace MyStructures //variables declared here act as a global variable
+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<streamsize>::max();
+
+
+namespace MyStructures //variables declared here act as a global variable
{
- template <typename T>
+
class Contact
{
public:
Contact() = default;
- Contact(const char* name, const short age);
+ Contact(char* name, const short age);
+
+ ~Contact();
+
+ 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);
- ~Contact() = default;
+ const char* GetStreet();
+ void SetStreet(char* street);
- Contact(const Contact& copy); //copy constructor
- Contact& operator=(const Contact& rhs); //copy assignment
+ const char* GetState();
+ void SetState(char* state);
- Contact(Contact&& move); //move constructor
- Contact& operator=(Contact&& rhs); //move assignment
+ const char* GetCity();
+ void SetCity(char* city);
+ int GetZip();
+ void SetZip(int zip);
- short GetAge();
- const char* GetName();
+ /*int InputInt(const char* prompt);*/
+ /*char* PromptCharInput(const char* prompt, long long maxlen);*/
- void SetAge(short age);
- void SetName(const char* name);
+ bool operator != (const Contact & rhs) const;
+
+
+ void Print() const;
- void Print();
- T GetCustomValue(T& newValue);
private:
- const char* name_{};
- short age_{ 0 };
- T custom_value_{}; //one type is declared, it will be custom
+ 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()
+ {
+
+ delete[] firstname_;
+ delete[] lastname_;
+ delete[] email_;
+ delete[] street_;
+ delete[] state_;
+ delete[] city_;
+ }
- };
-
- template<typename T>
- Contact<T>::Contact(const char* name, const short age)
+ 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_;
+
+
}
- template<typename T>
- Contact<T>::Contact(const Contact& copy)
+
+ 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;
}
- template<typename T>
- Contact<T>& Contact<T>::operator=(const Contact& rhs)
+
+ inline Contact::Contact(Contact&& move)
{
- // TODO: insert return statement here
+ *this = move;
}
- template<typename T>
- Contact<T>::Contact(Contact&& 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;
}
- template<typename T>
- Contact<T>& Contact<T>::operator=(Contact&& rhs)
+ inline const char* Contact::GetFirstName()
{
- // TODO: insert return statement here
+ return firstname_;
}
+ void Contact::SetFirstName(char* firstname)
+ {
+ firstname_ = firstname;
+ }
- template<typename T>
- short Contact<T>::GetAge()
+ inline const char* Contact::GetLastName()
{
- return 0;
+ return lastname_;
}
- template<typename T>
- const char* Contact<T>::GetName()
+ inline void Contact::SetLastName(char* lastname)
{
- return nullptr;
+ lastname_ = lastname;
}
- template<typename T>
- void Contact<T>::SetAge(short age)
+ inline const char* Contact::GetEmail()
{
+ return email_;
}
- template<typename T>
- void Contact<T>::SetName(const char* name)
+ inline void Contact::SetEmail(char* email)
{
+ email_ = email;
}
- template<typename T>
- inline void Contact<T>::Print()
+ inline const char* Contact::GetStreet()
{
+ return street_;
}
- template<typename T>
- T Contact<T>::GetCustomValue(T& newValue)
+ inline void Contact::SetStreet(char* street)
{
- custom_value_ = newValue
- return T();
+ 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 int Contact::InputInt(const char* prompt)
+ {
+ std::cout << prompt << std::endl;
+
+ std::cout.flush();
+
+ int data = 0;
+ std::cin >> data;
+ while (!std::cin)
+ {
+ std::cout << prompt << std::endl;
+ std::cin.clear();
+ cin.ignore(MAX_STREAM_SIZE, '\n');
+ std::cin >> data;
+
+ }
+
+ return data;
+ }*/
+
+ //inline char* Contact::PromptCharInput(const char* prompt, long long maxlen)
+ //{
+ // char* input = new char[maxlen];
+ // std::cout.flush();
+
+ // std::cout << prompt << std::endl;
+ // cin.get(input, maxlen, '\n');
+ // cin.ignore(MAX_STREAM_SIZE, '\n');
+ //
+ // while (!std::cin)
+ // {
+ // std::cout << prompt << std::endl;
+
+ // std::cin.clear();
+ //
+ // cin.get(input, maxlen, '\n');
+
+ // }
+ //
+ // return input;
+ //}
+
+ 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;
+ }
+
+
+
+ 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 \ No newline at end of file