CSC112 Spring 2016 Examples
//An example class with overloaded methods1#include <iostream>23using namespace std;45class Point {6public:7//overloaded constructors!8Point()9{10_x = 0;11_y = 0;12}1314Point(double _x, double _y)15{16this->_x = _x;17this->_y = _y;18}1920//overloaded methods for accessing x and y21double x()22{23return _x;24}2526void x(double val)27{28this->_x = val;29}3031double y()32{33return _y;34}3536void y(double val)37{38this->_y = val;39}40private:41//private attributes of the class42double _x;43double _y;44};454647int main()48{49Point *p1 = new Point;50Point *p2 = new Point(2.0, 3.0);5152cout << "(" << p2->x() << ", " << p2->y() << ")" << endl;53p1->x(4);54cout << "(" << p1->x() << ", " << p1->y() << ")" << endl;55}565758