aboutsummaryrefslogtreecommitdiff
path: root/Homework8/MyStructures/Contact.hpp
blob: 0d99fe9cb6d09a28333bd7d358a93d6000bec2fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef CONTACT_HPP
#define CONTACT_HPP
#include <iostream>
#include <cstring>
#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<streamsize>::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