Programming and Graphics

(Kiana) #1

6.3 Class definition 157


class fruit
{
public:
fruit();
fruit(q, w, ..., e);
string readcolor(a, b, ..., c) const;
void change(g, o, ..., x);
private:
...
};

The qualifiervoidindicates that the functionchange will return neither a
number, nor a word, nor a sentence, but will quietly carry out the requested
operation.


To change kiwi, we state in the main program:

kiwi.change (g, o, ..., x);

Public and private functions


If we declare a class function in the private section of the class, then
this function could be called from other class functions, but not from the main
program or any other external function.


Class implementation


Now we define the precise action taken by the member functions “fruit”,
“readcolor”, and “change” of the “fruit” class.


The implementation of the default fruit constructor reads:

fruit::fruit()
{
q=dvq;
w=dvw;
...
e=dve;
}

where “dvq”, “dvw”, etc., are specified default values that describe an object
of the fruit class.


The implementation of the parametered fruit constructor reads:

fruit::fruit(valueq, valuew, ..., valuee)
{
Free download pdf