Enter the code:
/**copyright (c) 2015, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: sum123.cpp* Author: Lin Haiyun * Completion date: June 12, 2015 * version number: v2.0** Problem Description: A line connected to the center of the circle: given a point p, which is connected to the center of the line, and the circle has two intersections. Based on the point and Circle (circle) classes defined above, a scheme is designed to output the coordinates of these two points. * Program Input: NO * program output: Output the intersection of two circles as required */#include <iostream> #include <cmath>using namespace Std;class circle;class Point {public:point (double a=0,double b=0): X (a), Y (b) {} Friend Ostream & operator<< (ostream &,const Point & amp;); friend void Crossover_point (Point &p,circle &c, point &p1,point &p2); The friend function protected:double X,y;};o of intersection Stream & operator<< (ostream &output,const point &p) {output<< "[" <<p.x<< "," < <p.y<< "]"; return output;} Class Circle:public point{public:circle (double a=0,double b=0,double r=0):P oint (A, B), radius (r) {} friend Ostream & amp;operator<< (ostream &,const Circle &); friend void Crossover_point (Point &p,circle &c, point &p1,point &amP;P2); The friend function protected:double radius;};/of intersection /overloaded operator "<<" to output circle information in a prescribed form ostream &operator<< (ostream &output,const circle &c) {output< < "center=[" <<c.x<< "," <<c.y<< "], r=" <<c.radius; return output;} void Crossover_point (Point &p, Circle &c, point &p1,point &p2) {p1.x = (c.x + sqrt (c.radius*c.radius/( 1+ ((C.Y-P.Y)/(c.x-p.x)) * ((C.Y-P.Y)/(c.x-p.x)))); p2.x = (c.x-sqrt (c.radius*c.radius/(1+ ((C.Y-P.Y)/(c.x-p.x)) * ((C.Y-P.Y)/(c.x-p.x)))); P1.y = (p.y + (p1.x-p.x) * (C.Y-P.Y)/(c.x-p.x)); P2.y = (p.y + (p2.x-p.x) * (C.Y-P.Y)/(c.x-p.x));} int main () {Circle C1 (3,2,4); Point P1 (P2,P3); Crossover_point (P1,C1, p2, p3); cout<< "point p1:" <<p1<<endl; cout<< "with Circle C1:" <<c1<<endl; The center of the cout<< "is connected with the circle at two o'clock, respectively:" <<endl; cout<< "Intersection 1:" <<p2<<endl; cout<< "Intersection 2:" <<p3<<endl; return 0;}
Operation Result:
Point Circle Relationship---3