#ifndef __FRACTION_H__ #define __FRACTION_H__ #include class Fraction { public: // initialize the fraction to NaN Fraction(); // initialize the fraction to i Fraction(int i); // initialize the fraction to numerator/denominator Fraction(int numerator, int denominator); Fraction operator+(Fraction rhs); Fraction operator-(Fraction rhs); Fraction operator*(Fraction rhs); Fraction operator/(Fraction rhs); // unary - operator Fraction operator-(); bool operator==(Fraction rhs); // return true iff the fraction is Not a Number bool NaN(); // return true iff the fraction is positive infinity bool Inf(); // return true iff the fraction is negative infinity bool NegInf(); // print the fraction as / to the stream os // the fraction must be in lowest terms, and the denominator must not // be negative (i.e. negative fractions must have the '-' in the numerator void print(ostream& os); // fill the buffer buf with the decimal value of the fraction to as // high a precision as possible without exceeding length len-1 // return false if len did not allow sufficient room to represent // NaN, Inf, or -Inf, or the number prior to the decimal point // expand may round off or truncate bool expand(char buf[], int len); // return the double best approximating the value of the fraction double toDouble(); }; ostream& operator<<(ostream& os, Fraction f); #endif