1 #include <iostream> 2 using namespace std; 3 //设计圆类和点类,判断点和圆的关系 4 class Point 5 { 6 public: 7 void setX(int x) 8 { 9 m_X = x; 10 } 11 int getX() 12 { 13 return m_X; 14 } 15 void setY(int y) 16 { 17 m_Y = y; 18 } 19 int getY() 20 { 21 return m_Y; 22 } 23 private: 24 int m_X; 25 int m_Y; 26 }; 27 class Circle 28 { 29 public: 30 void setR(int r) 31 { 32 m_R = r; 33 } 34 int getR() 35 { 36 return m_R; 37 } 38 void setCenter(Point center) 39 { 40 m_Center = center; 41 } 42 Point getCenter() 43 { 44 return m_Center; 45 } 46 private: 47 int m_R; 48 Point m_Center; 49 }; 50 void isInCircle(Circle &c,Point &p) 51 { 52 int a = c.getR()*c.getR(); 53 int b = (p.getX()-c.getCenter().getX())*(p.getX()-c.getCenter().getX())+(p.getY()-c.getCenter().getY())*(p.getY()-c.getCenter().getY()); 54 if(a == b) 55 { 56 cout<<"点在圆上"<<endl; 57 } 58 else if(a > b) 59 { 60 cout<<"点在圆内"<<endl; 61 } 62 else if(a < b) 63 { 64 cout<<"点在圆外"<<endl; 65 } 66 } 67 int main() 68 { 69 Point p; 70 p.setX(1); 71 p.setY(1); 72 Point pr; 73 pr.setX(1); 74 pr.setY(1); 75 Circle c; 76 c.setCenter(pr); 77 c.setR(1); 78 isInCircle(c,p); 79 return 0; 80 }
标签:16,int,void,Point,getCenter,getX,getY,2023.4 From: https://www.cnblogs.com/muzhaodi/p/17322568.html