/////////////////////////////////////////////////////////////// // point.cpp - represents a two dimensional point // // ver 1.1 // // // // Language: Visual C++, ver 6.0 // // Platform: Dell OptiPlex, Win NT 4.0 // // Application: HW#3, ECS500, Su 99 // // Author: Jim Fawcett, Instructor, CST 2-187 // // Syracuse Univ, (315) 443-3948 // // fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// #include "point.h" //----< coordinate constructor >------------------------------- // // note the use of an initialization sequence // you should always do this with constructors point::point(double x, double y) : _x(x), _y(y) { } //----< additive assignment >---------------------------------- point& point::operator+=(const point &p) { _x += p._x; _y += p._y; return *this; } //----< addition >--------------------------------------------- point point::operator+(const point &p) { point temp = *this; temp += p; return temp; } #ifdef TEST_POINT //----< test stub >-------------------------------------------- void main() { point p1, p2(1.5,-1.5), p3(2.0, 1.5); // coordinate ctor cout << p1 << ", " << p2 << ", " << p3 << endl; point p4 = p1+=p2; // invoke additive assignment // invoke compiler defined assignment cout << p1 << ", " << p2 << ", " << p3 << endl; p1 = p2 + p3; // invoke addition operator // invoke compiler defined assignment cout << p1 << ", " << p2 << ", " << p3 << endl; } #endif