根据实验要求,需要定义4个类:Point、Shape、Circle、Cylinder和Triangle,并实现它们之间的继承关系。下面是对应的C++代码:
* Point类
class Point { protected: int x; int y; public: Point(int x, int y) : x(x),
y(y) {} virtual ~Point() {} virtual void show() { cout << "Point[" << x << ","
<< y << "]" << endl; } virtual string getName() { return "Point"; } };
* Shape类
class Shape { public: virtual ~Shape() {} virtual double getArea() = 0;
virtual double getPerimeter() = 0; virtual string getName() = 0; };
* Circle类
class Circle : public Point, public Shape { protected: double