conversions/between-user-defined-types/point1.cc - Class Tripple implementation. | Lecture 4 - slide 24 : 40 Program 6 |
#include <cmath> #include <iostream> #include "point1.h" // Tripple: Tripple::Tripple(): a(0), b(0), c(0){ } Tripple::Tripple(int x, int y, int z): a(x), b(y), c(z){ } Tripple::Tripple(Point p): a(int(p.getx())), b(int(p.gety())), c(0){ } Tripple::operator Point() const { return Point(a, b); } std::ostream& operator<<(std::ostream& s, const Tripple& tr){ return s << "[" << tr.a << "," << tr.b << "," << tr.c << "]"; } // Point: Point::Point(): x(0.0), y(7.0){ } Point::Point(double x_coord): x(x_coord), y(20.0){ } Point::Point(double x_coord, double y_coord): x(x_coord), y(y_coord){ } Point::Point(Point& p): x(p.x + 1.0), y(p.y + 2.0){ } double Point::getx () const{ return x; } double Point::gety () const{ return y; } Point::operator double() const { return x + y; } std::ostream& operator<<(std::ostream& s, const Point& p){ return s << "(" << p.getx() << "," << p.gety() << ")" ; }