#include "feetinch4.h" //********************************************************** // Definition of member function simplify. This function * // checks for values in the inches member greater than 12 * // or less than 0. If such a value is found, the numbers * // in feet and inches are adjusted to conform to a * // standard feet and inches expression. Thus, 3 feet 14 * // inches would be adjusted to 4 feet 2 inches and 5 feet * // -2 inches would be adjusted to 4 feet 10 inches. * //********************************************************** void FeetInches::simplify() { inches = 12*feet + inches; feet = inches / 12; inches = inches % 12; } //********************************************** // Overloaded binary + operator. * //********************************************** FeetInches FeetInches::operator+(const FeetInches &right) const { FeetInches temp; temp.inches = inches + right.inches; temp.feet = feet + right.feet; temp.simplify(); return temp; } //********************************************** // Overloaded binary - operator. * //********************************************** FeetInches FeetInches::operator-(const FeetInches &right) const { FeetInches temp; temp.inches = inches - right.inches; temp.feet = feet - right.feet; temp.simplify(); return temp; } //************************************************ // Overloaded prefix ++ operator. Causes the * // inched member to be incremented. Returns the * // incremented object. * //************************************************ FeetInches FeetInches::operator++() { ++inches; simplify(); return *this; } //************************************************* // Overloaded postfix ++ operator. Causes the * // inches member to be incremented. Returns the * // value of the object before the increment. * //************************************************* FeetInches FeetInches::operator++(int) { FeetInches temp(feet, inches); inches++; simplify(); return temp; } //************************************************** // Overloaded > operator. Returns true if the * // current object is set to a value greater than * // that of right. * //************************************************** bool FeetInches::operator>(const FeetInches &right) const { if (feet > right.feet) return true; if (feet == right.feet && inches > right.inches) return true; return false; } //************************************************* // Overloaded < operator. Returns true if the * // current object is set to a value less than * // that of right. * //************************************************* bool FeetInches::operator<(const FeetInches &right) const { return right > *this; } //************************************************* // Overloaded == operator. Returns true if the * // current object is set to a value equal to that * // of right. * //************************************************* bool FeetInches::operator==(const FeetInches &right) const { if (feet == right.feet && inches == right.inches) return true; else return false; }