编写c++程序用来判断点在圆内(包括圆上)还是圆外,要求用坐标轴判断。
Point.h
#ifndef _POINT_H
#define _POINT_H
class Point
{
private:
int m_x;
int m_y;
public:
void setxy(int x,int y);
int getdistance(Point &p);
};
#endif
Circle.h
#ifndef _CIRCLE_H
#define _CIRCLE_H
#include"Point.h"
class Circle
{
private:
int m_r;
Point m_p; //对象作为成员变量
public:
void set(int x,int y,int r);
bool judge(Point &p);
};
#endif
Point.cpp
#include"Point.h"
void Point::setxy(int x,int y)
{
m_x=x;
m_y=y;
}
int Point::getdistance(Point &p)
{
return ((this->m_x-p.m_x)*(this->m_x-p.m_x)+(this->m_y-p.m_y)*(m_y-p.m_y));
}
Circle.cpp