Programming and Graphics

(Kiana) #1

162 Introduction to C++ Programming and Graphics


size = 1.2;
}

The implementation of the parametered constructor is:

fruit::fruit(string clr, string shp, float size)
{
color = clr;
shape = shp;
size = 2.3;
}

The implementation of the non-intrusivereadcolorfunction is:

string fruit::readcolor(bool Iprint) const
{
if(Iprint==true)
cout << color << endl;
return color;
}

The implementation of the mutatorchangecolorfunction is:

void fruit::changecolor(string clr)
{
color = clr;
}

The following main program defines and manipulates fruit class members:

int main()
{
bool Iprint = true;

fruit fig = fruit();
string figcolor = fig.readcolor(Iprint);
cout << figcolor << endl;

fruit apple = fruit("red", "round", 2.0);
string applecolor = apple.readcolor(Iprint);

apple.changecolor("yellow");
applecolor = apple.readcolor(Iprint);

return 0;
}
Free download pdf