class Point {
public:
Point( double x_, double y_) : x(x_), y(y_){}
double x, y ;
} ;
double square( double x) {
return x*x ;
}
double distance( const Point& p1, const Point& p2 ){
return sqrt( square( p1.x - p2.x) + square( p1.y - p2.y ) ) ;
}
class Shape {
public:
Shape( const Point& center_ ) : center(center_){}
Point center ;
virtual double area() const { return 0.0 ;}
virtual bool contains(const Point& point) const { return false ; }
} ;
class Circle : public Shape {
public:
Circle( Point center_, double radius_ ): Shape(center_), radius(radius_){}
double area() const {
return PI * square( radius ) ;
}
bool contains( const Point& point ) const {
return distance(point, center) < radius ;
}
double radius ;
} ;
class Rectangle : public Shape {
public:
Rectangle( Point center_, double width_, double height_ ) :
Shape(center_), width(width_), height(height_){}
double area() const {
return width * height ;
}
bool contains( const Point& point ){
return
point.x >= ( center.x - width / 2.0 ) &
point.x <= ( center.x + width / 2.0 ) &
point.y >= ( center.y - height / 2.0 ) &
point.y <= ( center.y + height / 2.0 ) ;
}
double width, height ;
} ;