/*
*Copyright (c) 2014,烟台大学计算机学院void change(int a[8][8]);
*All rights reserved.
*文件名称:main.cpp
*作者:苏强
*完成日期:2015年5月25日
*版本号:v1.0
*
*问题描述:建立点类Point和派生圆类circle,判断两个圆的大小关系
*/
#include <iostream>
#include<cmath>
using namespace std;
static double pi=3.14159;
class Point
{
protected:
double x,y;
public:
Point(double X,double Y):x(X),y(Y){}
friend ostream &operator <<(ostream &out,Point &p);
};
ostream &operator <<(ostream &out,Point &p)
{
out<<"("<<p.x<<","<<p.y<<")"<<endl;
return out;
}
class Circle:virtual public Point
{
protected:
double r;
public:
Circle(double X,double Y ,double R):Point(X,Y),r(R){}
friend ostream &operator <<(ostream &out,Circle &c);
double area();
friend bool operator>(Circle &c1,Circle &c2);
friend bool operator<(Circle &c1,Circle &c2);
friend bool operator>=(Circle &c1,Circle &c2);
friend bool operator<=(Circle &c1,Circle &c2);
friend bool operator==(Circle &c1,Circle &c2);
friend bool operator!=(Circle &c1,Circle &c2);
};
ostream &operator <<(ostream &out,Circle &c)
{
out<<"圆心:("<<c.x<<","<<c.y<<") 半径:"<<c.r<<endl;
return out;
}
double Circle::area()
{
return pi*r*r;
}
bool operator>(Circle &c1,Circle &c2)
{
if(c1.r-c2.r>0)
return true;
else
return false ;
}
bool operator<(Circle &c1,Circle &c2)
{
if(c1.r-c2.r<0)
return true;
else
return false ;
}
bool operator>=(Circle &c1,Circle &c2)
{
if(c1.r-c2.r<0)
return false;
else
return true;
}
bool operator<=(Circle &c1,Circle &c2)
{
if(c1.r-c2.r>0)
return false;
else
return true ;
}
bool operator==(Circle &c1,Circle &c2)
{
if(c1.r-c2.r==0)
return true;
else
return false ;
}
bool operator!=(Circle &c1,Circle &c2)
{
if(c1.r-c2.r!=0)
return true;
else
return false ;
}
int main()
{
Circle c1(3,2,4),c2(4,5,5);
cout<<"圆c1:"<<c1<<"面积是:"<<c1.area()<<endl;
cout<<"圆c2:"<<c2<<"面积是:"<<c2.area()<<endl;
cout<<"圆c1";
if(c1>c2) cout<<" 大于,";
if(c1<c2) cout<<" 小于,";
if(c1>=c2) cout<<" 大于等于,";
if(c1<=c2) cout<<" 小于等于,";
if(c1==c2) cout<<" 等于,";
if(c1!=c2) cout<<" 不等于,";
cout<<"圆c2"<<endl;
}