定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,新增属性有半径?定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/09 10:35:47
定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,新增属性有半径?定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,

定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,新增属性有半径?定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,
定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,新增属性有半径?
定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,新增属性有半径,方法有设置半径、返回半径、计算圆的周长和计算圆的面积.设计一个测试类,计算圆的周长和面积.

定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,新增属性有半径?定义一个点类,它包含两个成员变量:纵坐标和横坐标.通过继承一个点类设计一个圆类,
#include
using namespace std;
const double pi = 3.14;
//Point类,派生出Rectangle类和Circle类,计算各派生类对象的面积Area().
template
class Point
{
public:
Point(){}
Point(const T x,const T y);
Point& operator= (const Point&p);
public:
T x;
T y;
};
template
Point::Point(const T x,const T y)
{
this->x = x;
this->y = y;
}
template
Point& Point::operator= (const Point&p)
{
this->x = p.x;
this->y = p.y;
return *this;
}
template
class Shape
{
public:
virtual double Area() = 0;
};
template
class Rectangle:public Shape
{
public:
Rectangle(const Point& p1,const Point& p2);
double Area();
private:
Point pLT;
Point pRD;
};
template
Rectangle::Rectangle(const Point& p1,const Point& p2)
{
pLT = p1;
pRD = p2;
}
template
double Rectangle::Area()
{
T w = pLT.x - pRD.x;
T h = pLT.y - pRD.y;
if(w