Programming and Graphics

(Kiana) #1

186 Introduction to C++ Programming and Graphics


The only new feature is that we have replaced the statement:


private:

with the statement:


protected:

in anticipation of inheritance.


The flower class implementation is:


//--- FLOWER CLASS IMPLEMENTATION

flower::flower()
{
type = "tulip";
color = "black";
price = 4.99;
}

flower::flower(string ftype, string fcolor, float fprice)
{
type = ftype;
color = fcolor;
price = fprice;
}

string flower::gettype() const
{
return type;
}

string flower::getcolor() const
{
return color;
}

float flower::getprice() const
{
return price;
}

void flower::print() const
{
cout << type <<" "<< color <<" "<< "$"<<price << endl;
}
Free download pdf