// ========================================================================== // $Id: vector2d.cpp,v 1.6 2017/09/23 00:53:23 jlang Exp $ // CSI2372 example Code for lecture 4 // ========================================================================== // (C)opyright: // // Jochen Lang // SITE, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.site.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@site.uottawa.ca // ========================================================================== // $Log: vector2d.cpp,v $ // Revision 1.6 2017/09/23 00:53:23 jlang // Introduced references and const again for this version // // Revision 1.5 2017/09/13 16:21:06 jlang // Removed arrays, references and use of const. // // Revision 1.4 2014/10/22 20:29:25 jlang // Minor changes. // // Revision 1.3 2014/10/04 20:32:32 jlang // Minor change for better illustration. // // Revision 1.2 2014/10/01 18:04:03 jlang // Updated vector2d example // // Revision 1.1 2011/10/16 02:51:42 jlang // Added files for lecture 06 // // ========================================================================== #include #include #include "point2d.h" using std::cout; using std::endl; // class Vector2D : protected Point2D { class Vector2D : public Point2D { double d_length; public: // Vector2D(double _x=0.0, double _y=0.0) : d_x(_x), d_y(_y) { Vector2D(double _x=0.0, double _y=0.0) : Point2D(_x,_y) { d_length = std::sqrt(dot(*this)); print(); } // Not really needed here - could be: // Vector(const Vector2D& _oVect ) = default; Vector2D(const Vector2D& _oVect ) : Point2D(_oVect){ std::cout << "Must call cctor of base!" << std::endl; } double dot( const Vector2D& _oVect ) const { return d_x * _oVect.d_x + d_y * _oVect.d_y; } }; int main() { Vector2D v2DA( 0.5, 2.0 ); Vector2D v2DB( 2.0, 1.0 ); Point2D p2D( 1.0, 0.5 ); p2D.print(); v2DA.print(); cout << endl; p2D = v2DA.min( p2D ); p2D.print(); cout << endl; p2D = v2DA.min( v2DB ); p2D.print(); cout << endl; return 0; }