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
|
#include <string>
#include <iostream>
using namespace std;
class Address
{
public:
// ctor
Address(unsigned number, string street, string suffix, string city, string state, unsigned zip);
// accessors
unsigned getNumber() const;
string getStreet() const;
string getSuffix() const;
string getCity() const;
string getState() const;
unsigned getZip() const;
// mutators
Address & setNumber(unsigned number);
Address & setStreet(const string & street);
Address & setSuffix(const string & suffix);
Address & setCity(const string & city);
Address & setState(const string & state);
Address & setZip(unsigned zip);
// other: display the information in the invoking objects on 2 lines,
// as we would expect to see on an envelope
const Address & show() const;
private:
unsigned myNumber;
string myStreet;
string mySuffix;
string myCity;
string myState;
unsigned myZip;
};
int main()
{
Address a( 16000, "gfgfg", "Street", "fgdggd", "dg", 91344) ;
cout << a.getNumber() << " " << a.getStreet() << " " << a.getSuffix() <<
endl << a.getCity() << " " << a.getState() << " " << a.getZip() << endl;
cout<<endl;
Address loc[] =
{
{ 6401, "gdgdg", "dgd", "Woodland Hills", "CA", 91371 },
{ 4792, "sffs", "sfsf", "sfsf", "CA", 91371 },
{ 2001, "dgdg", "dgdg", "dgd", "CA", 91371 },
{ 1234, "dgd", "dgdg", "dg", "CA", 91375 },
{ 992, "dgd", "dg", "dgdg", "CA", 91375 }
};
for (unsigned i = 0; i < 5; i++)
{
cout << loc[i].getNumber() << " " << loc[i].getStreet() << " " << loc[i].getSuffix() << endl << loc[i].getCity() << " " << loc[i].getState() << " " << loc[i].getZip() << endl;
cout << "-------------------" << endl;
}
}
// member function definition //ctor
Address::Address(unsigned number, string street, string suffix, string city, string state, unsigned zip)
{
myNumber = number;
myStreet = street;
mySuffix = suffix;
myCity = city;
myState = state;
myZip = zip;
// if (!myNumber||myNumber<1 || myNumber>199999999) die("Invalid Number");
// if (myStreet == " ") die("Invalid Street");
// if (mySuffix==" ") die("Invalid Suffix");
// if (myCity == " ") die("Invalid City");
// if (myState == " ") die("Invalid State");
// if (!zip) die("Invalid Zip");
}
// Class member function definition // accessors
unsigned Address::getNumber() const
{
return this->myNumber;
}
string Address::getStreet() const
{
return myStreet;
}
string Address::getSuffix() const
{
return mySuffix;
}
string Address::getCity()const
{
return myCity;
}
string Address::getState()const
{
return myState;
}
unsigned Address::getZip() const
{
return myZip;
}
// Class member function definition // mutators
Address & Address::setNumber(unsigned number)
{
this->myNumber = number;
return *this;
}
Address & Address::setStreet(const string & street)
{
this->myStreet = street;
return *this;
}
Address & Address::setSuffix(const string & suffix)
{
this->mySuffix = suffix;
return *this;
}
Address & Address::setCity(const string & city)
{
this->myCity = city;
return *this;
}
Address & Address::setState(const string & state)
{
this->myState = state;
return *this;
}
Address & Address::setZip(unsigned zip)
{
this->myZip = zip;
return *this;
}
/*const Address & Address::show() const
{
}*/
bool die(const string & msg)
{
cerr << endl << "FATAL ERROR: " << msg << endl;
//exit(EXIT_FAILURE);
}
|