#ifndef RATIONAL_H #define RATIONAL_H #include class Rational { public: friend int operator ==(const Rational& r1, const Rational& r2); friend int operator <(const Rational& r1, const Rational& r2); friend int operator <=(const Rational& r1, const Rational& r2); friend int operator >(const Rational& r1, const Rational& r2); friend int operator >=(const Rational& r1, const Rational& r2); friend Rational operator +(const Rational& r1, const Rational& r2); friend Rational operator -(const Rational& r1, const Rational& r2); friend Rational operator -(const Rational& r); friend Rational operator *(const Rational& r1, const Rational& r2); friend Rational operator /(const Rational& r1, const Rational& r2); friend ostream& operator <<(ostream& outs, const Rational& r); friend istream& operator >>(istream& ins, Rational& r); //Input must always have a division sign; e.g., for 2, you use 2/1. //Input need not be in reduced form. double get_double() const; //Returns an equivalent value of type double. Rational(); Rational(int new_numerator, int new_denominator); Rational(int whole_number); private: void reduce(); //Changes the representation to reduced form //For example if numerator is 2 and denominator is 4 (for 2/4) //it changes it to numerator == 1 and denominator == 2 (for 1/2). //Adjusts minus sign so that the minus sign (if any) //is only on the numerator. //(Essentially converts things like 1/-2 to -1/2 and //-1/-2 to 1/2.) It is safest to call reduce before doing //any arithmetic in a member function or operator definition. int numerator; int denominator; }; #endif //RATIONAL_H