//定义点类、圆类
// 点类:数据成员包括横、纵坐标
// 圆类:
// 数据成员包括圆心(点类对象)、半径
// 成员函数void disRel(Circle & c)返回当前圆对象与另一个圆对象的距离关系:
// 相离、外切、相交、内切、同心
#include <iostream>
#include <cmath>
using namespace std;
class Point{
public:
int x,y;
void set(int,int);
};
void Point::set(int a,int b){
this->x=a;
this->y=b;
}
class Circle{
private:
Point x;
int r;
public:
void set(Point m,int n);
void disRel(Circle & c);
};
void Circle::set(Point m,int n){
this->x=m;
this->r=n;
}
void Circle::disRel(Circle & c){
Point a=this->x,b=c.x;
int q=(a.x-b.x)*(a.x-b.x);
int w=(a.y-b.y)*(a.y-b.y);
double l=q+w;
double h= sqrt(l);
double j=this->r+c.r;
if(h==j)
cout<<"相切"<<endl;
else
if(h>j)
cout<<"相离"<<endl;
else
if(h<j)
cout<<"相交"<<endl;
}
int main(){
Point a,b;
a.set(0,0);
b.set(3,4);
Circle x,y;
x.set(a,1);
y.set(b,1);
x.disRel(y);
return 0;
}
// 点类:数据成员包括横、纵坐标
// 圆类:
// 数据成员包括圆心(点类对象)、半径
// 成员函数void disRel(Circle & c)返回当前圆对象与另一个圆对象的距离关系:
// 相离、外切、相交、内切、同心
#include <iostream>
#include <cmath>
using namespace std;
class Point{
public:
int x,y;
void set(int,int);
};
void Point::set(int a,int b){
this->x=a;
this->y=b;
}
class Circle{
private:
Point x;
int r;
public:
void set(Point m,int n);
void disRel(Circle & c);
};
void Circle::set(Point m,int n){
this->x=m;
this->r=n;
}
void Circle::disRel(Circle & c){
Point a=this->x,b=c.x;
int q=(a.x-b.x)*(a.x-b.x);
int w=(a.y-b.y)*(a.y-b.y);
double l=q+w;
double h= sqrt(l);
double j=this->r+c.r;
if(h==j)
cout<<"相切"<<endl;
else
if(h>j)
cout<<"相离"<<endl;
else
if(h<j)
cout<<"相交"<<endl;
}
int main(){
Point a,b;
a.set(0,0);
b.set(3,4);
Circle x,y;
x.set(a,1);
y.set(b,1);
x.disRel(y);
return 0;
}