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
|
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Address {
private:
string streetNumber;
string street;
string city;
string state;
string zipcode;
public:
Address(const string& streetNumber, const string& street, const string& city, const string& state, const string& zipcode) : streetNumber(streetNumber), street(street), city(city), state(state), zipcode(zipcode) {}
string getStreetNumber() const {
return streetNumber;
}
string getStreet() const {
return street;
}
string getCity() const {
return city;
}
string getState() const {
return state;
}
string getZipcode() const {
return zipcode;
}
void change(string streetNumber, string street, string city, string state, string zipcode) {
this->streetNumber = streetNumber;
this->street = street;
this->city = city;
this->state = state;
this->zipcode = zipcode;
}
string toString() {
string result = "Street Number: " + streetNumber + " Street: " + street + "City: " + city + "State: " + state + "Zipcode: ";
return result;
}
};
int main() {
vector<Address> address;
string streetNumber, street, city, state, zipcode;
int n;
cout << "How many addresses are you entering? ";
cin >> n;
getline(cin, streetNumber );
for (int i = 0; i < n; ++i) {
cout << "Enter the street number: ";
getline(cin, streetNumber);
cout << "Enter the street: ";
getline(cin, street);
cout << "Enter the city: ";
getline(cin, city);
cout << "Enter the state: ";
getline(cin, state);
cout << "Enter the zipcode: ";
getline(cin, zipcode);
cout << endl;
Address p(streetNumber, street, city, state, zipcode);
Address.push_back(p);
}
// display addresses
for (int i = 0; i < address.size(); ++i) {
cout << address[i].toString() << endl;
}
return 0;
}
|