【黑马程序员】点圆位置判断 类 案例 完全自写

发布时间:2022-07-03 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了【黑马程序员】点圆位置判断 类 案例 完全自写脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

#include<iostream> using namespace std;

class Point { private:     int m_X;     int m_Y;

public:     void setX(int x)     {         m_X = x;     }     void setY(int y)     {         m_Y = y;     }     int getX()     {         return m_X;     }     int getY()     {         return m_Y;     } };

class Circle { private:     int m_R = 0;     Point Center;

public:     void setR(int r)     {         m_R = r;     }

    int getR()     {         return m_R;     }

    void setCenter(int x, int y)     {         Center.setX(x);         Center.setY(y);     }

    void judgement(Point& P)     {         /*cout << P.getX() << endl;         cout << getCenterX() << endl;         cout << P.getY() << endl;         cout << getCenterY() << endl;*/

        int distance = (P.getX() - Center.getX()) * (P.getX() - Center.getX())                       + (P.getY() - Center.getY()) * (P.getY() - Center.getY());

        //cout << distance << endl;         if (distance < (getR() * getR()))         {             cout << "点在圆内" << endl;         }         else if (distance == (getR() * getR()))         {             cout << "点在圆上" << endl;         }         else         {             cout << "点在圆外" << endl;         }     } };

int main() {     Point P;     P.setX(3);     //cout << P.getX() << endl;     P.setY(3);     //cout << P.getY() << endl;               Circle C;     C.setCenter(0, 0);     C.setR(5);     //cout << C.getCenterX() << endl;     C.judgement(P);

    system("pause");     return 0; }

脚本宝典总结

以上是脚本宝典为你收集整理的【黑马程序员】点圆位置判断 类 案例 完全自写全部内容,希望文章能够帮你解决【黑马程序员】点圆位置判断 类 案例 完全自写所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: