请设计一个描述形状的类Shape,Shape类中有两个成员函数,
(1)getArea0函数:用于计算形状的面积
(2)getLen0函数:用于计算形状的周长。
Shape类有两个派生类
(1)Rectangle类:表示矩形。
(2)Circle类:表示圆形
请编写程序实现以下功能
(1)计算不同边长的矩形的面积和周长,
(2)计算不同半径的圆的面积和周长。
class Shape {
public:
virtual ~Shape(){}
virtual int getArea() = 0;
virtual int getLen() = 0;
};
class Rectange
: public Shape
{
public:
Rectange(int w, int h) : m_width(w), m_height(h) {}
~Rectange() {}
virtual int getArea() { return m_width * m_height; }
virtual int getLen() { return (m_width + m_height) << 1; }
private:
int m_width = 0;
int m_height = 0;
};
class Circle
: public Shape
{
public:
Circle(int r): m_r(r) {}
~Circle() {}
virtual int getArea() { return m_r * m_r * 3.1415f; }
virtual int getLen() { return m_r * 3.1415f * 2; }
private:
int m_r = 0;
};