定义一个Point类,派生出Rectangle类和Circle类,计算各 派生类对象的面积Area().
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/22 11:28:42
定义一个Point类,派生出Rectangle类和Circle类,计算各 派生类对象的面积Area().
定义一个Point类,派生出Rectangle类和Circle类,计算各 派生类对象的面积Area().
定义一个Point类,派生出Rectangle类和Circle类,计算各 派生类对象的面积Area().
#include
using namespace std;
#define PI 3.14
class Point
{
public:
\x09Point() :m_x(0),m_y(0){}
\x09Point(double x,double y) :m_x(x),m_y(y){}
\x09~Point(){}
protected:
\x09double m_x;
\x09double m_y;
};
class Rectangle :public Point
{
public:
\x09Rectangle() :Point(){}
\x09Rectangle(double x,double y) :Point(x,y){}
\x09~Rectangle(){}
\x09double Area()
\x09{
\x09\x09return m_x * m_y;
\x09}
};
class Circle :public Point
{
public:
\x09Circle() :m_r(0){}
\x09Circle(double r) :m_r(r){}
\x09~Circle(){}
\x09double Area()
\x09{
\x09\x09return PI * m_r * m_r;
\x09}
private:
\x09double m_r;
};
int main()
{
\x09Rectangle rect(3.2,2.1);
\x09Circle circle(5.1);
\x09cout