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
|
class winery
{
public :
winery(const char * const name, const char * const location, const int acres, const int rating);
char* getName() const {return m_name; }
char* getLocation() const {return m_location; }
private :
char* m_name;
char* m_location;
int m_acres;
int m_rating;
};
winery::winery(const char * const name, const char * const location, const int acres, const int rating)
: m_acres( acres ), m_rating( acres )
{
if (name)
{
size_t len = strlen(name) + 1;
m_name = new char [len];
strcpy_s(m_name,len, name);
}
else // passing in empty name: name = "";
{
m_name = NULL;
}
if (location)
{
size_t len = strlen(location) + 1;
m_location = new char[len ];
strcpy_s(m_location,len,location);
}
else // passing in empty location: location = "";
{
m_location = NULL;
}
}
int main()
{
winery w = winery("Lopez Island Vinyard", "San Juan Islands", 7, 95);
// winery w = winery("", "", 7, 95); // play with empty name and location
std::cout << w.getName() << std::endl;
std::cout << w.getLocation() << std::endl;
return 0;
}
| |