/************************************************************************ * * * File: PointTest.cpp * * * * Author: Robb T. Koether * * * * Date: Oct 19, 1999 * * * * Purpose: This file implements the member functions and * * operators of the Point class * * * * Note: This is the "verbose" version of the Point class. * * The default constructor, the copy constructor, the * * assignment operator, and the destructor will print * * messages whenever they are called. * * * ************************************************************************/ // Header files #include #include #include "windowsetup.h" #include "point.h" using namespace std; // Function prototypes Point Midpoint(Point A, Point B); /************************************************************************ * * * Function: main * * * ************************************************************************/ int main() { WindowSetup(); // Test the constructors and the output operator cout << "Test the constructors and the output operator" << endl; Point P; // Test the default constructor Point Q(2, 3); // Test the other constructor Point R = Q; // Test the copy constructor cout << "P = " << P << endl; // Test the output operator cout << "Q = " << Q << endl; cout << "R = " << R << endl; // Test the assignment operator cout << endl << "Test the assignment operator" << endl; cout << "Assign Q to P" << endl; P = Q; // Test the assignment operator cout << "P = " << P << endl; // Test the inspectors cout << endl << "Test the inspectors" << endl; cout << "The x-coordinate of Q is " << Q.GetX() << endl; // Test GetX() cout << "The y-coordinate of Q is " << Q.GetY() << endl; // Test GetY() // Test the mutators cout << endl << "Test the mutators" << endl; cout << "Enter the x-coordinate of P: " << flush; float x; cin >> x; P.SetX(x); // Test SetX() cout << "Enter the y-coordinate of P: " << flush; float y; cin >> y; P.SetY(y); // Test SetY() cout << "P = " << P << endl; // Test the input operator cout << endl << "Test the input operator" << endl; cout << "Enter a point (x, y): " << flush; cin >> R; // Test the input operator cout << "R = " << R << endl; // Test the equality operators // Use equal points cout << endl << "Test the equality operators" << endl; if (P == P) // Test equality of equals cout << "P == P" << endl; else cout << "P != P" << endl; if (P != P) // Test inequality of equals cout << "P != P" << endl; else cout << "P == P" << endl; // Use unequal points if (P == Q) // Test equality of unequals cout << "P == Q" << endl; else cout << "P != Q" << endl; if (P != Q) // Test inequality of unequals cout << "P != Q" << endl; else cout << "P == Q" << endl; // Test the add and multiply functions cout << endl << "Test the addition and multiplication operators" << endl; cout << "P + Q = " << P + Q << endl; // Test addition of points cout << "5 * P = " << 5 * P << endl; // Test scalar multiplication // Test the distance function cout << endl << "Test the distance function" << endl; cout << "The distance from P to Q is " << P.Distance(Q) << endl; // Test the distance function // Call on the Midpoint() function Point M = Midpoint(P, Q); cout << "The midpoint of " << P << " and " << Q << " is " << M << endl; cout << endl << "Good-bye" << endl; return 0; } /************************************************************************ * * * Function: Midpoint * * * * Purpose: To find the midpoint of a segment defined by its * * endpoints * * * ************************************************************************/ Point Midpoint(Point A, Point B) { return 0.5 * (A + B); }