(4)定义友元函数int locate,判断点p与圆的位置关系(返回值<0圆内,==0圆上,>0 圆外);
#include运行结果:#include using namespace std;class Point{public: Point():x(0),y(0){} Point(double a,double b):x(a),y(b){} double distance(const Point &p)const; friend ostream & operator<<(ostream &,const Point &);protected: double x; double y;};double Point::distance(const Point &p) const{ double dx = x-p.x; double dy = y-p.y; return sqrt(dx*dx+dy*dy);}ostream & operator<<(ostream &output,const Point &p){ output<<"["< <<","< <<"]"< 0 圆外protected: double radius;};ostream &operator<<(ostream &output,const Circle &c){ output<<"Center=["< <<", "< <<"], r="< < 0)?"外":((locate(p1, c1)<0)?"内":"上"))< 0)?"外":((locate(p2, c1)<0)?"内":"上"))< 0)?"外":((locate(p3, c1)<0)?"内":"上"))<