定义点类为基类,其数据成员x和y为私有成员。再定义圆类继承点类,该点为圆的圆心,新增数据成员圆的半径。
在圆类中定义成员函数,其形式参数为一个点,判断该点是在圆内部、圆外还是圆上。
#include <iostream>
using namespace std;
class point
{
public:
point(int a,int b)
{
x=a,y=b;
}
int get_x()
{
return x;
}
int get_y()
{
return y;
}
private:
int x,y;
};
class circle:public point
{
public:
circle(int a,int b,int t):point(a,b)
{
r=t;
}
void show(point &P)
{
int temp;
temp=(get_x()-P.get_x())*(get_x()-P.get_x())+(get_y()-P.get_y())*(get_y()-P.get_y());
if(temp>=r*r)
if(temp>r*r)
{
cout<<"out"<<endl;
}
else
{
cout<<"on"<<endl;
}
else
{
cout<<"in"<<endl;
}
}
private:
int r;
};
int main()
{
int a,b,c,d,e;
while(cin>>a>>b>>c>>d>>e)
{
circle C(a,b,c);
point P(d,e);
C.show(P);
}
return 0;
}