| Class Point - a variant with explicit use of this. | Lecture 3 - slide 24 : 36 Program 2 |
// A variant of point.cc where we use this more than usual.
#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 this->x;
}
double Point::gety () const{
return this->y;
}
Point* Point::move(double dx, double dy){
this->x += dx; this->y += dy;
return this;
}
double Point::distance_to(Point p){
return sqrt((this->x - p.x) * (this->x - p.x) +
(this->y - p.y) * (this->y - p.y));
}
std::ostream& operator<<(std::ostream& s, const Point& p){
return s << "(" << p.getx() << "," << p.gety() << ")" ;
}