#include
#include
using namespace std;
#define PI 3.1415926
class Circle
{
public:Circle(void): x(0),y(0),r(0){};
Circle(double x,double y): x(x),y(y),r(0){};
Circle(double r): x(0),y(0),r(r){};
Circle(double x,double y,double r): x(x),y(y),r(r){};
~Circle() {};
void setP(double x,double y);
void setX(double x);
void setY(double y);
void setR(double r);
void set(double x,double y,double r);
double getX(void);
double getY(void);
double getR(void);
double getArea(void);
double getCirLen(void);
bool contain(double x,double y);
void show(void);
protected:double x;
double y;
double r;
};
void Circle::setP(double x,double y)
{
this->x = x;
this->y = y;
}
void Circle::setX(double x)
{
this->x = x;
}
void Circle::setY(double y)
{
this->y = y;
}
void Circle::setR(double r)
{
this->r = r;
}
void Circle::set(double x,double y,double r)
{
this->setP(x,y);
this->setR(r);
}
double Circle::getX(void)
{
return x;
}
double Circle::getY(void)
{
return y;
}
double Circle::getR(void)
{
return r;
}
double Circle::getArea(void)
{
return r*r*PI;
}
double Circle::getCirLen(void)
{
return r*PI*2;
}
bool Circle::contain(double x,double y)
{
double len = sqrt( (this->x -x) * (this->x -x) + (this->y -y) * (this->y -y) );
if (len <= this->r) return 1;
else return 0;
}
void Circle::show(void)
{
cout << "圆心:(" <
cout << "半径:" << this->getR() << endl;
cout << "面积:" << this->getArea() << endl;
cout << "周长:" << this->getCirLen() << endl;
}
int main()
{
Circle c(1,1,1);
c.show();
c.setX(2);
c.show();
c.setY(3);
c.show();
c.setR(4);
c.show();
c.setP(1,1);
c.show();
c.set(5,5,5);
c.show();
cout << "该圆" << ( c.contain(3,3)?"":"不" )<< "包含点(3,3)。" << endl;
return 0;
}
测试可行。
#include
#include
#define pi 3.14
using namespace std;
class point{
public:
point(double X=0,double Y=0){x=X;y=Y;}
double x,y;
};
class circle:public point{
public:
circle(double Radius=0,double X,double Y){radius=Radius;x=X;y=Y;area=pi*pi*radius;length=2*pi*radius;}
circle(const circle& Circle){area=Circle.area;radius=Circle.radius;length=Circle.length;}
void GetRadius()const{cout<<"半径:"<
cout<<"点与圆的关系:";
if(pow(x-Point.x,2)+pow(y-Point.y,2)>radius*radius){
cout<<"在圆外."<
else if(pow(x-Point.x,2)+pow(y-Point.y,2)==radius*radius){
cout<<"在圆上."<
else cout<<"在园内."<
private:
double area,radius,length;
};
int main(){
point Point(5,9);
circle Circle(4.0,2,3);
Circle.GetRadius();
Circle.GetArea();
Circle.GetLength();
Circle.Determine(Point);
return 0;
}