#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
public:
T x;
T y;
};
template
Point
{
this->x = x;
this->y = y;
}
template
Point
{
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
double Area();
private:
Point
Point
};
template
Rectangle
{
pLT = p1;
pRD = p2;
}
template
double Rectangle
{
T w = pLT.x - pRD.x;
T h = pLT.y - pRD.y;
if(w<0) w = -w;
if(h<0) h = -h;
return double(w * h);
}
//Circle
template
class Circle:public Shape
{
public:
Circle(const Point
double Area();
private:
Point
T r;
};
template
Circle
{
origin = p1;
this->r = r;
}
template
double Circle
{
return pi * r * r;
}
int main()
{
Point
Point
Rectangle
Circle
printf("Rectangle ' Area is %f\n", R.Area());
printf("Circle ' Area is %f\n", C.Area());
return 0;
}