-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddress.cpp
More file actions
97 lines (78 loc) · 2.46 KB
/
Address.cpp
File metadata and controls
97 lines (78 loc) · 2.46 KB
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
#include "Address.h"
#include <cstring>
Address::Address(const char* city, const char* zip, const char* street, const int number) : number(number){
this->city = this->createMemory(city);
strcpy(this->city, city);
this->zip = this->createMemory(zip);
strcpy(this->zip, zip);
this->street = this->createMemory(street);
strcpy(this->street, street);
}
Address::~Address(){
delete [] this->city;
delete [] this->zip;
delete [] this->street;
}
Address::Address(const Address &a){
this->city = this->createMemory(a.city);
strcpy(this->city, a.city);
this->zip = this->createMemory(a.zip);
strcpy(this->zip, a.zip);
this->street = this->createMemory(a.street);
strcpy(this->street, a.street);
this->number = a.number;
}
void Address::setCity(const char* city){
delete [] this->city;
this->city = this->createMemory(city);
strcpy(this->city, city);
}
void Address::setZip(const char* zip){
delete [] this->zip;
this->zip = this->createMemory(zip);
strcpy(this->zip, zip);
}
void Address::setStreet(const char* street){
delete [] this->street;
this->street = this->createMemory(street);
strcpy(this->street, street);
}
void Address::setNumber(int number) {
this->number = this->number;
}
const char* Address::getCity() const{
return this->city;
}
const char* Address::getZip() const{
return this->zip;
}
const char* Address::getStreet() const{
return this->street;
}
int Address::getNumber() const {
return this->number;
}
char* Address::createMemory(const char* str) const{
return new char[strlen(str) + 1];
}
void Address::show() const {
std::cout << "Address: [ city: " << this->city << " | zip: " << this->zip << " | street: " << this->street << " | number: " << this->number << " ]";
}
Address& Address::operator=(const Address& that){
if(this == &that) return *this;
delete [] this->city;
delete [] this->zip;
delete [] this->street;
this->city = this->createMemory(that.city);
strcpy(this->city, that.city);
this->zip = this->createMemory(that.zip);
strcpy(this->zip, that.zip);
this->street = this->createMemory(that.street);
strcpy(this->street, that.street);
this->number = that.number;
return *this;
}
std::ostream& operator<<(std::ostream& os, const Address& that){
os << "Address: [ city: " << that.city << " | zip: " << that.zip << " | street: " << that.street << " | number: " << that.number << " ]";
return os;
}