Notes, Thursday, September 27
Previous page
|
Next page
Working on Assignment 3
Here are the pieces that were/will be discussed in class this week.
There are three classes
CatalogEntry,
CatalogNode, and
Catalog. Their header files are
And here are implementations of some of the functions and operators.
- Computing the number of entries in the catalog:
size.cxx.
- Making the catalog empty without leaking memory:
makeEmpty.cxx.
- Inserting an entry into the catalog:
operator +=.
- Opening and reading from a text file:
case 'f'.
Using colors
(This was not explained in class in detail.)
Here is how you can add colors to your MovingObject-s.
Add a private variable
Then in the constructor you can do, e.g.,
color = CDraw::randomLightColor ();
As an example of how to use the
enumerated type
enum Color { black, blue, gray, lime, red, white, yellow };
you can give your MovingObject-s a black perimeter
this way, in the output operator:
// output
ostream& operator << ( ostream& out, const MovingObject& mo )
{
const int DIAMETER = 50;
CDraw::setColor (mo.color);
CDraw::fillCircle (mo.x, mo.y, DIAMETER);
CDraw::setColor (CDraw::black);
CDraw::drawCircle (mo.x, mo.y, DIAMETER);
return out;
}
Previous page
|
Next page
|
Back to top
© 2002 Karl Winklmann
3:40 PM, Thursday, December 12, 2002