/**************************************************************** distance.h Header file for declaration of Distance class. Must be included by any file using Distance objects. "&" on parameter types means passing by reference --more efficient since avoids passing copies of variables --make "const" if not changing the var referenced Make methods "const" if does not alter object data. ****************************************************************/ #include <iostream> using namespace std; class Distance { private: int feet; float inches; static int inUnits; public: enum units {Feet, Inches}; // Constructors Distance(const int& ft = 0, const float& in = 0.0); Distance(const float& in); // Access to private data--set and get methods void setDist(const int& ft = 0, const float& in = 0.0); void setUnits(const int& units = Inches); units getUnits(); const float getDist() const; const float getInches() const; const int getFeet() const; // Other methods void prompt(); void display(ostream& out = cout) const; friend ostream& operator<<(ostream&, const Distance&); // Operator overloads // Almost always return a Distance obj so can // do things like d3 = d2 = d1++ = d4 + d5; Distance operator+(const Distance& d) const; Distance operator-(const Distance& d) const; Distance operator*(const float& f) const; Distance operator*(const int& i) const; Distance operator/(const float& f) const; Distance operator/(const int& i) const; //increment by inches Distance& operator++(); // Prefix Distance operator++(int); // Postfix Distance& operator+=(const Distance& d); //boolean comparison operators bool operator==(const Distance& d) const; bool operator!=(const Distance& d) const; bool operator>(const Distance& d) const; bool operator<=(const Distance& d) const; bool operator<(const Distance& d) const; bool operator>=(const Distance& d) const; // Hey, we can make our own cast!!! operator float(); };