Description
定义一个圆类,私有数据成员包括圆心的横、纵坐标及圆的半径,公有函数成员包括带参数的构造函数和圆心距计算函数,其它所需函数自行添加。判断两圆的位置关系是相交(intersectant)、相离(disjoint)或相切(tangent)。(PI=3.1415 用宏定义)
Input
首先是一个整数n,表示有n组数据
每组数据由6个float型数据组成,前三个表示第一个圆的圆心横、纵坐标及半径;后三个表示第二个圆的圆心横、纵坐标及半径.
Output
两圆的位置关系
Sample Input
3
1.0 0.0 1.0 3.0 0.0 1.0
1.2 0.0 1.0 3.0 0.0 1.0
0.0 2.0 2.12 6.35 0.12 2.56
Sample Output
They are tangent
They are intersectant
They are disjoint
//判断圆的位置关系
#include<stdio.h>
#include<iostream>
#define PI=3.1415
using namespace std;
class Y
{
public:
Y(float h1,float z1,float r1,float h2,float z2,float r2)
{
H1=h1;
Z1=z1;
R1=r1;
H2=h2;
Z2=z2;
R2=r2;
}
~Y(){};
float getlength(){return (H1-H2)*(H1-H2)+(Z1-Z2)*(Z1-Z2);}
float getall(){return (R1+R2)*(R1+R2);}
float getall2(){return (R1-R2)*(R1-R2);}
private:
float H1,H2,Z1,Z2,R1,R2;
};
int main()
{
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++){
float r1,r2,h1,h2,z1,z2;
scanf("%f%f%f%f%f%f",&h1,&z1,&r1,&h2,&z2,&r2);
Y r(h1,z1,r1,h2,z2,r2);
if(r.getlength()>r.getall())
printf("They are disjoint\n");
if(r.getlength()<r.getall()&&r.getlength()!=r.getall2())
printf("They are intersectant\n");
if(r.getlength()==r.getall()||r.getlength()==r.getall2())
printf("They are tangent\n");
}}