My Method 1:
1 #include<iostream> 2 3 class Point{ 4 int cX,cY; 5 public: 6 void setPoint(int x,int y){ 7 cX=x;cY=y; 8 } 9 int getPointX(){ 10 return cX; 11 } 12 int getPointY(){ 13 return cY; 14 } 15 }; 16 class Circle{ 17 int cRadius;Point cCenter; 18 public: 19 void setCircle(int radius,Point center){ 20 cRadius=radius;cCenter=center; 21 } 22 int getRadius(){ 23 return cRadius; 24 } 25 int getCenterX(){ 26 return cCenter.getPointX(); 27 } 28 int getCenterY(){ 29 return cCenter.getPointY(); 30 } 31 }; 32 int main(){ 33 Point p1,cp;Circle c1; 34 p1.setPoint(7,0);cp.setPoint(0,0); 35 c1.setCircle(8,cp); 36 if((c1.getCenterX()-p1.getPointX())*(c1.getCenterX()-p1.getPointX())+ 37 (c1.getCenterY()-p1.getPointY())*(c1.getCenterY()-p1.getPointY())> 38 c1.getRadius()*c1.getRadius()) 39 std::cout<<"点在圆外\n"<<std::endl; 40 else if(((c1.getCenterX()-p1.getPointX())*(c1.getCenterX()-p1.getPointX())+ 41 (c1.getCenterY()-p1.getPointY())*(c1.getCenterY()-p1.getPointY())== 42 c1.getRadius()*c1.getRadius())) 43 std::cout<<"点在圆上\n"<<std::endl; 44 else 45 std::cout<<"点在圆内\n"<<std::endl; 46 system("pause"); 47 return 0; 48 }
Teacher's practice:
1 #include<iostream> 2 class Point{ 3 int cX,cY; 4 public: 5 void setPoint(int x,int y){ 6 cX=x;cY=y; 7 } 8 int getPointX(){ 9 return cX; 10 } 11 int getPointY(){ 12 return cY; 13 } 14 }; 15 class Circle{ 16 intcRadius; Point cCenter; . 17 public : 18 is void setCircle ( int RADIUS, Point Center) { . 19 cRadius = RADIUS; cCenter = Center; 20 is } 21 is int getRadius () { 22 is return cRadius; 23 is } 24 Point getCenter () { 25 return cCenter; 26 is } 27 }; 28 int main () { 29 point P1, cp; // declare two points, p1 is an arbitrary point, cp is the center 30 circle C1; // declaration circle 31 is p1.setPoint ( 0 , . 5 ); // Assignment point 32 cp.setPoint ( 0 , 0 ); // Assignment center 33 is c1.setCircle ( . 6 , CP); // set the center and radius of the circle 34 is 35 IF ( (c1.getCenter () getPointX () -. p1.getPointX ()) * 36 (c1.getCenter () getPointX () -. p1.getPointX ()) + 37 [ (c1.getCenter () getPointY () -. P1 .getPointY ()) * 38 is (c1.getCenter () getPointY () -. p1.getPointY ())> 39 c1.getRadius () * c1.getRadius ()) 40 :: COUT << STD " point on the outer circle \ n-\ n- " ; 41 is the else IF . ((c1.getCenter () getPointX () - p1.getPointX ()) * 42 is . (c1.getCenter () getPointX () -p1.getPointX ()) + 43 is (c1.getCenter () getPointY () -. p1.getPointY ()) * 44 is (c1.getCenter () getPointY () -. p1.getPointY ()) == 45 C1. getRadius () * c1.getRadius ()) 46 is STD :: COUT << " point on the circle \ n-\ n- " ; 47 the else 48 STD :: COUT << " points within circle \ n-\ n- " ; 49 System ( 'pause"); 50 return 0; 51 }