C++点和圆的关系

#include <iostream>
class point
{
    int x;
    int y;
public:
    void setXY(int a,int b)
    {
        x=a;
        y=b;
    }
    void setXY1(){
        int x1,y1;
        std::cout<<"please input X position of point"<<std::endl;
        std::cin>>x1;
        std::cout<<"please input Y position of point"<<std::endl;
        std::cin>>y1;
        x = x1;
        y = y1;
    }
    int getX()
    {
        return x;
    }
    int getY()
    {
        return y;
    }
};
class circle
{
    point center;
    int r;
public:
    void setR(int a)
    {
        r=a;
    }
    void setcenter (point b)
    {
        center =b;
    }
    point getcenter()
    {
        return center;
    }
    int getR()
    {
        return r;
    }
};
int main() {
    circle a;
    point center;
    center.setXY(10,10);
    a.setR(10);
    a.setcenter(center);
    point b;
    b.setXY(10,21);
    int length1 = a.getcenter().getX() - b.getX();
    int length2 = a.getcenter().getY() - b.getY();
    int total = length1*length1+length2*length2;
    int c = a.getR();
    if(total>c*c)
    {
        std::cout<<"point is outside the circle"<<std::endl;
    } else if (total == c*c )
    {
        std::cout<<"point is on the circle"<<std::endl;
    } else
    {
        std::cout<<"point is inside the circle"<<std::endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值