#ifndef LPOINT_H #define LPOINT_H /////////////////////////////////////////////////////////////// // lpoint.h - represents a labeled two dimensional point // // ver 1.2 // // // // 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 labeled point in a plane. Public Interface: ================= lpoint p; void construction lpoint 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 lpoint p1 to standard output cin >> p1; get lpoint p1 from standard input */ /////////////////////////////////////////////////////////////// // build process // /////////////////////////////////////////////////////////////// // files required: // // lpoint.h, lpoint.cpp // // // // compiler command: // // cl /GX /DTEST_POINT lpoint.cpp // /////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 : 24 Jun 99 - first release ver 1.1 : 03 Jul 99 - added insertion and extraction operators ver 1.2 : 06 Jul 99 - removed insertion and extraction operators from lpoint as they are not needed, can use those from point - fixed bug in lpoint::get(...) so it can collect labels with embedded spaces - removed using namespace std from this header file */ // #include #include #include "point.h" class lpoint : public point { public: lpoint(double x=0, double y=0, const std::string &label=""); lpoint operator+(const lpoint &lp); virtual void put(std::ostream &out) const; virtual void get(std::istream &in); std::string& label(); private: std::string _label; }; //----< access label >----------------------------------------- inline std::string& lpoint::label() { return _label; } //----< display point >---------------------------------------- // // display labeled points of the form (1.4,-3.3,"lpoint p") // inline void lpoint::put(std::ostream &out) const { out << '(' << _x << ',' << _y << ',' << _label << ')'; } //----< get points from stream >------------------------------- // // get labeled points of the form (1.4,-3.3,"lpoint p") // inline void lpoint::get(std::istream &in) { char ch; in >> ch >> _x >> ch >> _y >> ch; _label.erase(); in >> ch; do { _label += ch; in.get(ch); } while(ch != ')'); } #endif