/******************************************************* FILE NAME = rational.h (rational.h) PROGRAMMER NAME - Justin C. Miller DATE - 09/17/2003 BUGS - I believe that everything works properly DESCRIPTION - This program declares new functions for Problem 1 *******************************************************/ #include using namespace std ; class rational { // Problem 1: #3, overloaded << and >> friend ostream & operator<<(ostream &, const rational &) ; friend istream & operator>>(istream &, rational &) ; public: // constructors rational (); // default constructor rational (int i); // constructs the rational i/1 rational (int i, int j); // constructs the rational i/j rational (const rational &); // copy constructor // accessor functions int numerator () const; int denominator () const; // Problem 1: #1, ceiling and floor int ceiling(void) const ; int floor(void) const ; // assignments void operator = (const rational &); void operator += (const rational &); void operator -= (const rational &); void operator *= (const rational &); void operator /= (const rational &); // comparison // when called as p.compare(q), this function returns 1 if p > q, 0 if p = q, and -1 if p < q int compare (const rational &) const; private: // data areas int top; int bottom; // This operation is used internally. // normalize() reduces the numerator and the denominator of the rational to smallest // possible values. For example, normalize() will reduce 200/450 to 4/9. To do this // normalize() will have to compute the greatest common divisor (gcd) of the numerator // and the denominator and then divide. // normalize() is used after every arithmetic operation involving rationals to ensure // that the numerator and the denminator do not become too large. void normalize (); }; // Problem 1: #2, overloaded +,-,*,/ // PROTOTYPES rational operator+(const rational &, const rational &) ; rational operator-(const rational &, const rational &) ; rational operator*(const rational &, const rational &) ; rational operator/(const rational &, const rational &) ;