判断点圆关系 (30 分)

判断点圆关系 (30 分)
输入平面上的一个点的坐标,以及一个圆的圆心坐标和半径,输出该点到原点的距离,并判断该点在圆内,圆外还是在圆周上。
在圆外时,将输出“outside",在圆内时,输出"inside",在圆周上时,输出“on"。
下面已经给出了点类Point的部分定义,请将其函数定义补充完整,并添加对圆类Circle的完整定义。

输入格式说明:
格式如下:
点的x坐标 点的y坐标 圆心的x坐标 圆心的y坐标 圆的半径
输入样例:
在一行中给出点坐标和圆心坐标及半径:
2 3 1 1 3
输出样例:
在这里给出相应的输出。例如:
3.61 inside

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class Point {
private:
    double x, y;
public:
    Point();
    Point(double x_, double y_);
    double distance();
    double distance(const Point& p);
    double getX() { return x; }
    double getY() { return y; }
    void setX(double x_);
    void setY(double y_);
};
Point::Point() { double x = 0; double y = 0; }
Point::Point(double x_, double y_)
{
    this->x = x_; this->y = y_;
}
double Point::distance() {
    return sqrt(this->x * this->x + this->y * this->y);
}
double Point::distance(const Point& p)
{
    return sqrt((this->x - p.x) * (this->x - p.x) + (this->y - p.y) * (this->y - p.y));
}
void Point::setX(double x_)
{
    cout << this->x << endl;
}
void Point::setY(double y_)
{
    cout << this->y << endl;
}
class Circle
{
private:
    Point p1;
    double r;
public:
    Circle(Point& p ,double r):p1(p)
    {
        this->r = r;
    }
    string judge(Point &p)
    {
        if (p.distance(p) > r)
            return "outside" ;
        else if (p.distance(p) == r)
            return "on";
        else
            return "inside" ;
    }
};

int main() {
    double x1, y1, x2, y2, r;
    cin >> x1 >> y1 >> x2 >> y2 >> r;
    Point p(x1, y1);
    Point ctr(x2, y2);
    Circle c(ctr, r);
    cout << setprecision(3) << p.distance() << " " << c.judge(p) << endl;
}

  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值