#ifndef POINT_H #define POINT_H /////////////////////////////////////////////////////////////// // point.h - represents two dimensional points // // ver 1.1 // // // // Language: Visual C++, ver 6.0 // // Platform: Dell OptiPlex, Win NT 4.0 // // Application: HW#3, ECS500, Su 99 // // Author: Jim Fawcett, Instructor, CST 2-187 // // Syracuse Univ, (315) 443-3948 // // fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// /* Class Operations: ================= Models a point in a plane. Public Interface: ================= point p; void construction sets x and y coordinates to zero point p(1.5,2.3); construction with coordinate values p.x() = -2.3; modify p's x coordinate p.y() = 7.2; modify p's y coordinate double x = p.x(); read p's x coordinate double y = p.y(); read p's y coordinate p1 += p2; add p2's coordinates to p1, modifying p1 p1 p2 + p3; assign the sum of p2 and p3 coordinates to p1 cout << p1; send point p1 to standard output cin >> p1; get p1 from standard input */ /////////////////////////////////////////////////////////////// // build process // /////////////////////////////////////////////////////////////// // files required: // // point.h, point.cpp // // // // compiler command: // // cl /GX /DTEST_POINT point.cpp // /////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 - 24 Jun 99 - first release ver 1.1 - 03 Jul 99 - added extraction operator - added insertion operator - added put() and get() functions ver 1.2 - 07 Jul 99 - removed using namespace std from this header file */ // #include class point { public: // no copy constructor need point(double x=0, double y=0); // coordinate constructor // also servers as void ctor point operator+(const point &p); // addition operator point& operator+=(const point &p); // additive assignment double& x(); // access x coordinate double& y(); // access y coordinate virtual void put(std::ostream &out) const; // send point to stream virtual void get(std::istream &in); // get point from stream protected: double _x, _y; }; //----< access x coordinate >---------------------------------- // only inline and template function bodies are allowed in header inline double& point::x() { return _x; } //----< access y coordinate >---------------------------------- inline double& point::y() { return _y; } //----< display point >---------------------------------------- inline void point::put(std::ostream &out) const { out << '(' << _x << ',' << _y << ')'; } //----< insert point into stream >----------------------------- inline std::ostream& operator<<(std::ostream &out, const point &p) { p.put(out); return out; } //----< read point >------------------------------------------- inline void point::get(std::istream &in) { char ch; in >> ch >> _x >> ch >> _y >> ch; // (1.4,-3.2) } //----< extract point from stream >---------------------------- inline std::istream& operator>>(std::istream &in, point &p) { p.get(in); return in; } #endif