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: Overload the relational operator (6 kinds) on the circle class so that it can compare the size of two circles by the area of the circle. Self-compiled main function complete test * program input: NO * program output: Compare the size of two circles as required */#include <iostream> #include <cmath>using namespace Std;class Point{public:point (Double a=0,double b=0): X (a), Y (b) {} PROTECTED:DOUBL e x, y;}; Class Circle:public Point//circle is a common derived class of the point class {public:circle (double a=0,double b=0,double r=0): Point (A, B), radius (R) {} double area () const; Calculate Circle Area friend Ostream &operator<< (ostream &,const Circle &); Overloading the relational operator operator so that it can compare the size of two circles by the area of a circle; bool Operator> (const circle &); BOOL operator< (const Circle &); BOOL Operator>= (const Circle &); BOOL Operator<= (const Circle &); BOOL operator== (const Circle &); BOOL Operator!= (const Circle &);p rotected:double radius;};/ /Calculate Circle Area Double Circle::area () const{return 3.14159*radiUs*radius;} Overload 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;} Overloaded relational operator (type) operator, allowing it to compare the size of two circles by the area of a circle; bool Circle::operator> (const Circle &c) {return (This->radius-c.radius) > 1e-7;} BOOL circle::operator< (const Circle &c) {return (C.radius-this->radius) > 1e-7;} BOOL Circle::operator>= (const Circle &c) {return! *this < c);} BOOL Circle::operator<= (const Circle &c) {return! *this > C);} BOOL circle::operator== (const Circle &c) {return abs (This->radius-c.radius) < 1e-7;} BOOL Circle::operator!= (const Circle &c) {return abs (This->radius-c.radius) > 1e-7;} int main () {Circle C1 (3,2,4), C2 (4,5,5); The area of cout<< "round C1 (" <<c1<< ") is" <<c1.area () <<endl; The area of cout<< "Round C2 (" <<c2<< ") is" <<c2.area() <<endl; cout<< "Round C1"; if (C1>C2) cout<< "Circle C1 greater than Circle C2." <<endl; if (C1<C2) cout<< "Circle C1 less than Circle C2." <<endl; if (C1>=C2) cout<< "Circle C1 is greater than or equal to round c2." <<endl; if (C1<=C2) cout<< "Circle C1 is less than or equal to round c2." <<endl; if (C1==C2) cout<< "Circle C1 equals circle C2." <<endl; if (C1!=C2) cout<< "Circle C1 not equal to round c2." <<endl; return 0;}
Operation Result:
Point Circle Relationship---2