/*烟台大学计算机学院学生
*All right reserved.
*文件名称:圆的比较
*作者:王雅萍
*完成日期:2014年4月27日
*版本号:v1.0
*对任务及求解方法的描述部分:圆的比较
*我的程序:*/
#include <iostream>
#include <cmath>
using namespace std;
class point
{
protected:
double x,y;
public:
point(double xx,double yy):x(xx),y(yy){}
double getx()
{
return x;
}
double gety()
{
return y;
}
~point()
{
}
friend ostream& operator <<(istream &putout,point &c);
};
ostream& operator <<(ostream &putout,point &c)
{
putout<<"("<<c.getx()<<","<<c.gety()<<")"<<endl;
return putout;
}
class circle:public point
{
private:
double r;
public:
circle(double xx,double yy,double rr):
point(xx,yy),r(rr){}
~circle()
{
}
friend ostream& operator <<(ostream &putout,circle &c);
double area()
{
return 3.14*r*r;
}
bool operator >=(circle c);
bool operator <(circle c);
bool operator <=(circle c);
bool operator >(circle c);
bool operator ==(circle c);
bool operator !=(circle c);
};
ostream& operator <<(ostream &putout,circle &c)
{
putout<<"("<<c.getx()<<","<<c.gety()<<")"<<endl;
putout<<"半径"<<c.r<<endl;
return putout;
}
bool circle::operator >=(circle c)
{
if(area()>=c.area())
return true;
return false;
}
bool circle::operator <(circle c)
{
if(*this>=c)
return false;
return true;
}
bool circle::operator <=(circle c)
{
if(area()<=c.area())
return true;
return false;
}
bool circle::operator >(circle c)
{
if(*this<=c)
return false;
return true;
}
bool circle::operator ==(circle c)
{
if(area()==c.area())
return true;
return false;
}
bool circle::operator !=(circle c)
{
if(*this==c)
return false;
return true;
}
int main( )
{
circle c1(3,2,4),c2(4,5,5); //c2应该大于c1
cout<<"圆c1: "<<c1;
cout<<"圆c2: "<<c2;
cout << "下面比较两个圆的大小:\n";
if (c1 > c2) cout << "c1>c2" << endl;
if (c1 < c2) cout << "c1<c2" << endl;
if (c1 == c2) cout << "c1=c2" << endl;
if (c1 != c2) cout << "c1≠c2" << endl;
if (c1>= c2) cout << "c1≥c2" << endl;
if (c1 <= c2) cout << "c1≤c2" << endl;
return 0;
}
圆的比较
最新推荐文章于 2022-08-09 17:16:16 发布