Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          operators/vers1/point.cc - Definition of Point member functions.Lecture 4 - slide 40 : 40
Program 2

// Definition of Point members, including the Point operator members. 

#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) const{
    return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}

Point Point::operator+(const Point& p){
  return Point(x+p.x, y+p.y);
}

Point Point::operator++(int){   // int means Postfix ++
  x++; y++; 
  return *this;
}

bool Point::operator==(const Point& p){
  return std::abs(p.x - x) <= 3.0 && std::abs(p.y - y) <= 3.0;
}

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