Programming and Graphics

(Kiana) #1

156 Introduction to C++ Programming and Graphics


public:
fruit();
fruit(q, w, ..., e);
~fruit();
...
private:
...
};

To abandon kiwi, we state


kiwi = ~fruit()

Accessor function


To query the members of the fruit class on their color, we introduce the
accessor member functionreadcolor. The class definition reads:


class fruit
{
public:
fruit();
fruit(q, w, ..., e);
~fruit();
string readcolor(a, b, ..., c) const;
...
private:
...
};

The qualifierstringindicates that the functionreadcolorwill return a string
of characters in the form of a word or sentence describing the color. The qualifier
constindicates that the function is non-intrusive, that is, it is an accessor.


To read the color of kiwi, we state in the main program:

string chroma;
chroma = kiwi.readcolor (a, b, ..., c);

Mutator function


To convert one type of fruit into another, we introduce the mutator mem-
ber functionchange. The class definition reads:

Free download pdf