//****************************************************************// // // // Copyright (c) 1997. // // Dr. Michael A. Redmond // // // // This software may not be distributed further without permission from // // Dr Michael A. Redmond. // // // // This software is distributed WITHOUT ANY WARRANTY. No claims are made // // as to its functionality or purpose. // // // // Author: Dr Michael A. Redmond // // Date: 2/11/97 // // // // //**************************************************************************// // point.h: declaration of Point ADT // conditional compilation to avoid trying to include same thing twice #ifndef POINT_H #define POINT_H #include // io library typically used with c++ - has some improvements over stdio // (which still can be used, but usually isn't) // a major advantage of iostream is that its operators can be overloaded // so that user defined class objects can be displayed/read with the // same interface - see below // Point ADT: class description // Defines class and its interface to the world // implementation is in point.cpp class Point { friend class Tw_Board; // Tw_Board needs access to GetRow and GetCol friend class Tw_Link; // Tw_Link needs access to GetRow and GetCol // public interface can be used by anybody public: // member functions // constructors Point(); Point(int row, int col); // inspectors Point Adjust(int horiz, int vert) const; // mutators - establish new values of attributes (data members) // facilitators bool PointsEqual(const Point &right) const; // horizontal distance between two points int HorizDist(Point secpoint) const; // vertical distance between two points int VertDist(Point secpoint) const; // city block distance between two points int CityBlockDist(Point secpoint) const; // crow flight distance between two points float CrowDist(Point secpoint) const; // some stream facilitators // write to stream void Insert(ostream &sout) const; // read from stream void Extract(istream &sin); // protected interface can be used by objects that are in class, // and objects that are in a subtype class (derived class) protected: // inspectors // return values of attributes (data members) int GetRow() const; int GetCol() const; // mutators // establish new values of attributes (data members) void SetRow(int row); void SetCol(int col); // private members can only be used by other member functions and // operators of this class // typically all attributes (data members) go here private: // data members int RowNo; int ColNo; }; // below overloads standard c++ operators so that they can be used // with point class objects, so syntax is like with ints floats etc // // Point ADT: auxiliary operator description ostream& operator<<(ostream &sout, const Point &s); istream& operator>>(istream &sin, Point &r); bool operator==(const Point &left, const Point &right); #endif