C++编程小练习 ———求两圆心的距离及判断两圆是否相交
C++ 程序完成“圆形”以下功能:
定义一个Point类,其属性包括点的坐标,提供计算两点之间距离的
定义一个圆形类,其属性包括圆心和半径
创建两个圆形对象,提示用户输入圆心坐标和半径,判断两个圆是否相交,并输出结果
Point.h
#ifndef POINT_H_
#define POINT_H_
class Point {
public:
Point();
Point(double x, double y);
~Point();
//计算两点间的距离
static double getDistance(const Point &A,
const Point &B);
private:
double x;
double y;
};
#endif
point.cpp
#include <math.h>
#include "Point.h"
Point::Point() {
x = 0;
y = 0;
}
Point::Point(double x, double y) {
this->x = x;
this->y = y;
}
Point::~Point() {
}
double Point::getDistance(const Point &A,
const Point &B) {
double dis = sqrt(pow(fabs(A.x - B.x), 2) +