unique-pointers/point.cc - The usual implementation of class Point - nothing of particular interest. | Lecture 4 - slide 15 : 40 Program 2 |
// Member definitions for the Point class. Nothing of particular interest. #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){ } Point::~Point(){ std::cout << "Point deleted" << std::endl; } double Point::getx () const{ return x; } double Point::gety () const{ return y; } void Point::displace(double dx, double dy){ x += dx; y += dy; } double Point::distance_to(const Point& p){ return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)); } std::ostream& operator<<(std::ostream& s, const Point& p){ return s << "(" << p.getx() << "," << p.gety() << ")" ; }