Source of testfrnd1.cpp


  1: // Filename: TESTFRND.CPP
  2: // Purpose:  To test overloading of the output operator <<.

  4: #include <iostream>
  5: using namespace std;


  8: class Point
  9: {
 10:     friend ostream& operator<</*void Display*/(/* inout */ ostream& outputStream,
 11:                         /* in */    const Point& p);
 12:     // Pre:  The output stream outputStream is open.
 13:     // Post: Point p has been output in the form (x, y).
 14:     //       outputStream is still open.

 16: public:

 18:     Point(/* in */ int x = 0,
 19:           /* in */ int y = 0);

 21: private:

 23:     int x;
 24:     int y;
 25: };


 28: int main()
 29: {
 30:         Point p(1,2);
 31: //        Display(cout, p);
 32: cout << p;
 33:         cout << endl;

 35:         return 0;
 36: }


 39: //******************************************************************
 40: Point::Point(/* in */ int xInit,
 41:              /* in */ int yInit)
 42: {
 43:     x = xInit;
 44:     y = yInit;
 45: }


 48: //******************************************************************
 49: ostream& operator<</*void Display*/(/* inout */ ostream& outputStream,
 50:              /* in */    const Point& p)
 51: // Pre:  The output stream outputStream is open.
 52: // Post: Point p has been output in the form (x, y).
 53: //       outputStream is still open.
 54: {
 55:     outputStream << "(" << p.x << ", " << p.y << ")";
 56:     return outputStream;
 57: }