哪位C++大虾帮下小弟,要源程序,急!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:00:19
题目:请编写一个抽象类Shape,在此基础上派生出类Rectangle和Circle,二者都有计算对象面积的函数GetArea()、计算对象周厂的函数GetPerim()。

class Shape
{
public:
Shape(double x=0.0, double y=0.0):m_width(x),m_length(y){}
~Shape();
Shape(const Shar& rhs){m_width=rhs.m_width;m_length=rhs.m_length;}
virtual double GetPerim();
virtual doubleGetArea();

private:
double m_width;
double m_length;
};

class Rectangle public : Shape
{
public:
Rectangle(double x=0.0, double y=0.0):m_width(x),m_length(y){}
~Rectangle();
Rectangle(const Rectangle& rhs){m_width=rhs.m_width;m_length=rhs.m_length;}
virtual double GetPerim(){return (m_width + m_length) * 2;}
virtual doubleGetArea(){return m_width * m_length;}
};

class Circle public : Shape
{
public:
Circle(double x=0.0, double y=0.0):m_pie(x),m_r(y){}
~Circle();
Circle(const Circle& rhs){m_pie=rhs.m_pie;m_r=rhs.m_r;}
virtual double GetPerim(){return 2 * m_pie * m_r;}
virtual doubleGetArea(){return m_pie * m_r * m_r;}
priveta: