请创建一个抽象类Shape,在此基础上继承出Rectangle和Circle类,并让这三者都具备计算对象面积和周长的函数getAreaC和getPerimC
发布时间
阅读量:
阅读量
#include
#include
using namespace std;
class Shape
{
public:
Shape(){}
~Shape(){}
public:
virtual double getArea() const = 0;
virtual double getPerim() const = 0;
private:
};
class Rectangle : public Shape
{
public:
Rectangle(double _length, double _width) : length(_length), width(_width){}
~Rectangle(){}
public:
double getArea() const {return length * width;}
double getPerim() const {return 2 * (length + width);}
private:
double length;
double width;
};
class Circle : public Shape
{
public:
Circle(double _radius) : radius(_radius){}
~Circle(){}
全部评论 (0)
还没有任何评论哟~
