// CS2 Chung, // - Default arguments (convenient for constructors) // - Review Friend Function: not a member function, but can access private // data of its parameters. #include #include class Point { private: double x; double y; public: Point(double init_x = 0, double init_y = 0) // default arguments { x = init_x; y = init_y; } /* Point() { cout << "Enter x and y for a point: "; cin >> x >> y; } Ambigous!!!! */ void display() { cout << "(" << x << ", "; cout << y << ")" << endl; } friend Point middle(Point& p1, Point& p2); }; // Point Point::middle(Point& p1, Point& p2) Wrong! not an mem. func.! Point middle(Point& p1, Point& p2) { double x_mid, y_mid; x_mid = (p1.x + p2.x) / 2; y_mid = (p1.y + p2.y) / 2; Point midpoint(x_mid, y_mid); return midpoint; } void main() { Point p0, p1(1,2), p2(-1); middle(p1,p2); cout << "The midle point between two points: "; middle(p1,p2).display(); }