Category : Files from Magazines
Archive   : MICROCAD.ZIP

Output of file : CADSHAPE.HPP contained in archive : MICROCAD.ZIP
// Figure 4 for "A Little CAD with C++"
// Copyright 1988 Bruce Eckel
// Permission required to distribute source

// file: cadshape.hpp
/* A polymorphic base class for all shapes.
Almost all functions are virtual, so they
can be redefined in derived classes. Then
we can make a list of shapes and draw()
each shape in the list without knowing
exactly what it is. */
class cadshape {
unsigned x_center, y_center;
// virtual functions must have SOME
// definition in the base class, even
// if it's just empty:
virtual ~cadshape() {}
virtual void draw() {}
virtual void erase() {}
move(unsigned new_x, unsigned new_y ) {
x_center = new_x;
y_center = new_y;
draw(); // call proper virtual function
unsigned long
range( unsigned xr, unsigned yr ) {
// a measure of distance between a
// selected point and this object's center
unsigned long xx =
xr > x_center ?
xr - x_center : x_center - xr;
// (ternary if-then-else)
unsigned long yy =
yr > y_center ?
yr - y_center : y_center - yr;
xx *= xx;
yy *= yy;
// delta x squared + delta y squared:
return xx + yy;

  3 Responses to “Category : Files from Magazines
Archive   : MICROCAD.ZIP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: