//以面向对象和面向过程两种思想来判断一个点是在圆内还是在圆外
#include<iostream>
using namespace std;
class Point
{
private:
int x0;
int y0;
public:
void setxy(int _x0, int _y0)
{
x0 = _x0;
y0 = _y0;
}
int getx()
{
return x0;
}
int gety()
{
return y0;
}
};
class Circle
{
public:
void setxyr(int _x1, int _y1, int _r)
{
x1 = _x1;
y1 = _y1;
r = _r;
}
void judge(int x0, int y0)
{
int a = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) - r*r;
if (a > 0)
{
cout << "it is out of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
}
void judge(Point &p)
{
int a = (x1 - p.getx())*(x1 - p.getx()) + (y1 - p.gety())*(y1 - p.gety()) - r*r;
if (a > 0)
{
cout << "it is out of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
}
private:
int x1;
int y1;
int r;
};
//面向过程
void main0()
{
int x0 = 1;
int y0 = 1;
int x1 = 2;
int y1 = 2;
int r = 3;
int a = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) - r*r;
if (a > 0)
{
cout << "it is out of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
system("pause");
}
//面向对象
void main()
{
Point myp;
myp.setxy(1,1);
Circle c1;
c1.setxyr(2,2,3);
c1.judge(myp);
system("pause");
}
#include<iostream>
using namespace std;
class Point
{
private:
int x0;
int y0;
public:
void setxy(int _x0, int _y0)
{
x0 = _x0;
y0 = _y0;
}
int getx()
{
return x0;
}
int gety()
{
return y0;
}
};
class Circle
{
public:
void setxyr(int _x1, int _y1, int _r)
{
x1 = _x1;
y1 = _y1;
r = _r;
}
void judge(int x0, int y0)
{
int a = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) - r*r;
if (a > 0)
{
cout << "it is out of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
}
void judge(Point &p)
{
int a = (x1 - p.getx())*(x1 - p.getx()) + (y1 - p.gety())*(y1 - p.gety()) - r*r;
if (a > 0)
{
cout << "it is out of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
}
private:
int x1;
int y1;
int r;
};
//面向过程
void main0()
{
int x0 = 1;
int y0 = 1;
int x1 = 2;
int y1 = 2;
int r = 3;
int a = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0) - r*r;
if (a > 0)
{
cout << "it is out of the circle";
}
if (a < 0)
{
cout << "it is in the circle";
}
system("pause");
}
//面向对象
void main()
{
Point myp;
myp.setxy(1,1);
Circle c1;
c1.setxyr(2,2,3);
c1.judge(myp);
system("pause");
}