-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddress.cpp
More file actions
97 lines (83 loc) · 1.8 KB
/
Address.cpp
File metadata and controls
97 lines (83 loc) · 1.8 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"
int SafelyInputInteger() {
long num;
while (true) {
cin >> num;
if (cin.fail()) {
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
continue;
}
break;
}
return num;
}
const int MAX_STRING_SIZE = 100;
Address::Address()
{
this->street = "";
this->streetNumber = 0;
this->zipcode = 0;
this->city = "";
this->phone = "";
}
Address::Address(string street, int streetNumber, int zipcode, string city, string phone)
{
this->setStreet(street);
this->setStreetNumber(streetNumber);
this->setZipcode(zipcode);
this->setCity(city);
this->setPhone(phone);
}
Address::~Address()
{
}
void Address::setStreet(string street)
{
this->street = street;
}
void Address::setStreetNumber(int streetNumber)
{
this->streetNumber = streetNumber;
}
void Address::setZipcode(int zipcode)
{
this->zipcode = zipcode;
}
void Address::setCity(string city)
{
this->city = city;
}
void Address::setPhone(string phone)
{
this->phone = phone;
}
void Address::inputAddress()
{
string newStrings;
int newNumbers;
cin.ignore();
cout << "Enter your Street Name: ";
getline(cin,newStrings);
this->setStreet(newStrings);
cout << "Enter your Street Number: ";
newNumbers = SafelyInputInteger();
this->setStreetNumber(newNumbers);
cin.ignore();
cout << "Enter your City: ";
getline(cin, newStrings);
this->setCity(newStrings);
cout << "Enter your zipcode: ";
newNumbers = SafelyInputInteger();
this->setZipcode(newNumbers);
cin.ignore();
cout << "Enter your phone: ";
getline(cin, newStrings);
this->setPhone(newStrings);
this->print();
}
void Address::print() const
{
cout << "Delivery address is currently set as: " << this->street << " " << this->streetNumber
<< " , " << this->city << " , " << this->zipcode << endl << "Phone: " << this->phone << endl;
}