, . . , .
, Shape.
NodeShape
#include graphlib.h
class NodeShape
{
protected:
// ,
//
float x, y;
int fillpat;
NodeShape *next;
public:
//
NodeShape (float h=0, float v=0, int fill=0);
//
virtual void Draw (void) const;
//
void InsertAfter (NodeShape *p);
NodeShape *DeleteAfter (void);
NodeShape *Nexn (void);
};
(x,y) , fillpat. Draw next, NodeShape . InsertAfter DeleteAfter , . Next .
NodeShape shapelst.h
NodeShape
NodeShape CNode. , , .
//. ,
// next
NodeShape::NodeShape (float h, float v, int fill):
x (h), y (v), fillpat (fill)
{
next = this;
}
. CircleFigure RectangleFigure NodeShape. Draw, Draw . Area Perimeter . CircleFigure .
// CircleFigure, NodeShape
class CircleFigure: public NodeShape
{
protected:
//
float radius;
public:
//
CircleFigure (float h, float v, float r, int fill);
//
virtual void Draw (void) const;
};
//.
CircleFigure:: CircleFigure (float h, float v, float r, int fill):
NodeShape (h, v, fill), radius (r)
{}
//
// Draw
void CircleFigure::Draw (void) const
|
|
{
NodeShape::Draw();
DrawCircle (x, y, radius);
}
shapelst.h RightTriangle, , .
y
(x, y)
x
, , NodeShape listHeader. , InsertAfter . , , - -:
listHeader
//
NodeShape listHeader, *p;
float x, y, radius, height;
//
p = &listHeader;
// 4
for (int i=0; i<4; i++)
{
//
cout << x y:;
cin >> x >> y;
if (i % 2 == 0) // 1 ,
{
cout << : ;
cin >> radius;
// i
p -> InsertAfter (new Circle (x, y, radius, i));
}
else // i ,
{
cout <<
: ;
cin >> base >> height;
p -> InsertAfter (new RightTriangle (x, y, radius, i));
}
//
p = p -> Next();
}
. Circle, RightTriangle. Draw , Draw .
p = listHeader.Next();
while (p!= &listHeader)
{
p -> Draw();
p = p->Next();
}
.