📄 2-2.cpp
字号:
#include <iostream>
#include <cmath>
using namespace std;
class Point /*点类定义*/
{
public: /*外部借口,公有成员函数*/
friend double Distance(Point &p,Point &q);
Point(float xx = 0,float yy = 0) /*构造函数*/
{
X=xx;
Y=yy;
}
Point(Point &p) /*拷贝构造函数*/
{
X=p.X;
Y=p.Y;
}
float GetX() {return X;};
float GetY() {return Y;};
private: /*私有数据成员*/
float X,Y;
};
double Distance(Point &p,Point &q)
{
float result;
return sqrt((p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y));
}
class circle
{
private: /*私有数据成员*/
Point H;
float R;
public: /*外部借口,公有成员函数*/
circle (circle &); /*拷贝构造函数*/
circle (Point h,float r); /*构造函数*/
Point GeTH() {return H;}
float GetR() {return R;}
};
circle::circle (Point h,float r):H(h)
{
H=h;
R=r;
}
int main()
{
float px,py,qx,qy;
float r1,r2;
char temp;
cout << "请输入两个点的坐标(px,py),(qx,qy):" << endl;
cin >>px>>py>>qx>>qy;
cout << "请输入两个圆的半径r1,r2:" << endl;
cin >>r1>>r2;
Point p1(px,py),p2(qx,qy);
circle c1(p1,r1),c2(p2,r2);
double d= Distance (p1,p2);
cout << "圆心间距离是:" << d << endl;
cout << "半径和是:" << (r1+r2) << endl;
if (r1+r2<d)
cout << "两圆相离" << endl;
else
cout << "两圆相交" << endl;
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -