// CSE 303, Spring 2009, Marty Stepp // This client program uses Point objects. // // To compile these files: // g++ -g -Wall -c Point.cpp // g++ -g -Wall -o use_point use_point.cpp Point.o #include #include "Point.h" using namespace std; int main() { // construct two Point objects Point p1(1, 2); Point p2(4, 6); // call some methods on them cout << "p1 is: (" << p1.getX() << ", " << p1.getY() << ")" << endl; cout << "p2 is: (" << p2.getX() << ", " << p2.getY() << ")" << endl; cout << "dist : " << p1.distance(p2) << endl; return 0; } // alternate version that uses pointers int main2() { // construct two Point objects (using pointers) Point* p1 = new Point(1, 2); Point* p2 = new Point(4, 6); // call some methods on them cout << "p1 is: (" << p1->getX() << ", " << p1->getY() << ")" << endl; // p1 is: (1, 2) cout << "p2 is: (" << p2->getX() << ", " << p2->getY() << ")" << endl; // p2 is: (4, 6) cout << "dist : " << p1->distance(*p2) << endl; // must always free (delete) heap-allocated objects delete p1; delete p2; return 0; }