zoukankan      html  css  js  c++  java
  • 面向对象方法——求解点与圆的关系

     1 #include<iostream>
     2 using namespace std;
     3 class MyPoint
     4 {
     5 public:
     6     void setPoint(int _x1, int _y1)
     7     {
     8         x1 = _x1;
     9         y1 = _y1;
    10     }
    11     int getX1()
    12     {
    13         return x1;
    14     }
    15     int getY1()
    16     {
    17         return y1;
    18     }
    19 private:
    20     int x1;
    21     int y1;
    22 };
    23 class AdvCircle
    24 {
    25 public:
    26     void setCircle(int _r, int _x0, int _y0)
    27     {
    28         r = _r;
    29         x0 = _x0;
    30         y0 = _y0;
    31     }
    32 public:
    33     int judge(MyPoint &myp)
    34     {
    35         int dd = (myp.getX1() - x0)*(myp.getX1() - x0) + (myp.getY1() - y0)*(myp.getY1() - y0);
    36         if (dd<=r*r)
    37         {
    38             return 1;//园内
    39         }
    40         else
    41         {
    42             return 0;
    43         }
    44     }
    45 protected:
    46 private:
    47     int r;
    48     int x0;
    49     int y0;
    50 };
    51 
    52 
    53 
    54 
    55 void main()
    56 {
    57     AdvCircle c1;
    58     MyPoint p1;
    59     c1.setCircle(2, 3, 3);
    60     p1.setPoint(7, 7);
    61     //在圆形1,不在为0
    62     int tag=c1.judge(p1);
    63     if (tag==1)
    64     {
    65         cout << "在圆内" << endl;
    66     }
    67     else
    68     {
    69         cout << "不在圆内" << endl;
    70     }
    71     system("pause");
    72     return;
    73 }
  • 相关阅读:
    公共控件
    winform 窗口 属性
    ADO
    笔记备忘
    常识 备忘
    Symbol
    Promise
    定义类 属性 方法 执行
    x is string str ======x is string 变量名
    ManualResetEvent多线程进行,全部完成后,回调
  • 原文地址:https://www.cnblogs.com/hnzsb-vv1130/p/6641367.html
Copyright © 2011-2022 走看看