#include <iostream> #include <cmath> using namespace std; class Point { public: Point(double a,double b):x(a),y(b) {} double getx() { return x; } double gety() { return y; } friend ostream&operator << (ostream&,Point&); protected: double x,y; }; ostream&operator << (ostream &output,Point &p) { output<<"("<<p.getx()<<","<<p.gety()<<")"<<endl; return output; } class Circle:public Point { public: Circle(double a,double b,double c):Point(a,b),r(c) {} double getr() { return r; } friend ostream&operator << (ostream&,Circle&); friend double locate(Circle&,Point&); protected: double r; }; ostream&operator << (ostream &output,Circle &c) { output<<"("<<c.getx()<<","<<c.gety()<<")"<<" "; output<<"r="<<c.getr()<<endl; return output; } double locate(Point &po,Circle &ci) { double d,num; d=sqrt(pow((ci.getx()-po.getx()),2)+pow((ci.gety()-po.gety()),2)); if(d>ci.getr()) num=1; else if(d==ci.getr()) num=0; else num=-1; return num; } int main( ) { Circle c1(3,2,4),c2(4,5,5); //c2应该大于c1 Point p1(1,1),p2(3,-2),p3(7,3); //分别位于c1内、上、外 cout<<"圆c1: "<<c1; cout<<"点p1: "<<p1; cout<<"点p1在圆c1之"<<((locate(p1, c1)>0)? "外":((locate(p1, c1)<0)? "内":"上"))<<endl; cout<<"点p2: "<<p2; cout<<"点p2在圆c1之"<<((locate(p2, c1)>0)? "外":((locate(p2, c1)<0)?"内":"上"))<<endl; cout<<"点p3: "<<p3; cout<<"点p3在圆c1之"<<((locate(p3, c1)>0)?"外":((locate(p3, c1)<0)?"内":"上"))<<endl; return 0; }
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemp4MjExMzE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" >
情绪:我没吃饭了没!
版权声明:本文博客原创文章。博客,未经同意,不得转载。
时间: 2024-10-04 04:27:51