Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'                containers/priority-queue/point.cc - The implementation of class Point and in particular operator<.Lecture 6 - slide 11 : 40
Program 3

#include <cmath>
#include <iostream>
#include "point.h"

Point::Point(double x_coord, double y_coord): x(x_coord), y(y_coord){
}

Point::Point(): x(0.0), y(0.0){
}

double Point::getx () const{
  return x;
}

double Point::gety () const{
  return y;
}

void Point::move(double dx, double dy){
    x += dx; y += dy;
}

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

// funny implementation - compares sum of x and y coordinates
bool operator<(const Point& p, const Point& q){  
  return p.x + p.y < q.x + q.y;
}

std::ostream& operator<<(std::ostream& s, const Point& p){
  return s << "(" << p.getx() << "," << p.gety() << ")" ;
}