⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 point.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#include "point.h"
#include <cmath>
#include <sstream>

Point::Point(double px, double py)
  : x(px), y(py)
{}
  
Point::Point()
  : x(0), y(0)
{}

  
bool operator == (const Point& lhs, const Point& rhs)
{
    return lhs.x == rhs.x && lhs.y == rhs.y;
}

bool operator != (const Point& lhs, const Point& rhs)
{
    return ! (lhs == rhs);
}

bool operator  < (const Point& lhs, const Point& rhs)
{
    return lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y < rhs.y);
}

bool operator  > (const Point& lhs, const Point& rhs)
{
    return rhs < lhs;
}

bool operator <= (const Point& lhs, const Point& rhs)
{
    return ! (lhs > rhs);
}

bool operator >= (const Point& lhs, const Point& rhs)
{
    return ! (lhs < rhs);
}

double Point::distanceFrom(const Point& p) const
{
    return sqrt( (x - p.x)*(x-p.x) + (y - p.y)*(y - p.y));
}

string Point::tostring() const
{
    ostringstream out;
    out << "(" << x << ", " << y << ")";
    return out.str();
}

ostream& operator << (ostream& os, const Point& p)
{
    os << p.tostring();
    return os;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -