码迷,mamicode.com
首页 > 其他好文 > 详细

13周 项目2 圆的比较

时间:2014-05-21 10:09:26      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:blog   class   c   code   ext   http   

#include <iostream>
#include <cmath>
using namespace std;
class Point
{

public:
    Point(double a,double b):x(a),y(b) {}
    double getx()
    {
        return x;
    }
    double gety()
    {
        return y;
    }
    friend ostream&operator << (ostream&,Point&);
protected:
    double x,y;
};
ostream&operator << (ostream &output,Point &p)
{
    output<<"("<<p.getx()<<","<<p.gety()<<")"<<endl;
    return output;
}
class Circle:public Point
{

public:
    Circle(double a,double b,double c):Point(a,b),r(c) {}
    friend ostream&operator << (ostream&,Circle&);
    bool operator > (Circle &c);
    bool operator < (Circle &c);
    bool operator >= (Circle &c);
    bool operator <= (Circle &c);
    bool operator == (Circle &c);
    bool operator != (Circle &c);

protected:
    double r;
};
ostream&operator << (ostream &output,Circle &c)
{
    output<<"("<<c.getx()<<","<<c.gety()<<")"<<" ";
    output<<"半径:"<<c.r<<endl;
    return output;
}
bool Circle::operator < (Circle &c)
{
    if(r<c.r)
        return true;
    else
        return false;
}
bool Circle::operator > (Circle &c)
{
    if(r>c.r)
        return true;
    else
        return false;
}
bool Circle::operator >= (Circle &c)
{
    if(*this<c)return false;
    return true;
}
bool Circle::operator <= (Circle &c)
{
    if(*this>c)return false;
    return true;
}
bool Circle::operator == (Circle &c)
{
    if(*this>=c&&*this<=c)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);
    cout<<"c1:"<<c1<<endl;
    cout<<"c2:"<<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;
    if (c1 <= c2) cout << "c1≤c2" << endl;
    return 0;
}
bubuko.com,布布扣

13周 项目2 圆的比较,布布扣,bubuko.com

13周 项目2 圆的比较

标签:blog   class   c   code   ext   http   

原文地址:http://blog.csdn.net/zjx211314/article/details/26393733

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!