// This ensures that this file is included at most once // in any program, as there may be multiple include // statements. #pragma once #include //////////////////////// // Class declarations // //////////////////////// class Rational; /////////////////////////// // Function declarations // /////////////////////////// // All function definitions are in the file 'Rational.cpp'. // These functions query their arguments, but do not // change them. // Calculate p + q. Rational add( Rational const &p, Rational const &q ); // Calculate p + n. Rational add( Rational const &p, int const n ); // Calculate n + q. Rational add( int const n, Rational const &q ); // Calculate p - q. Rational sub( Rational const &p, Rational const &q ); // Calculate p - n. Rational sub( Rational const &p, int const n ); // Calculate n - q. Rational sub( int const n, Rational const &q ); // Calculate p*q. Rational mul( Rational const &p, Rational const &q ); // Calculate p*n. Rational mul( Rational const &p, int const n ); // Calculate n*q. Rational mul( int const n, Rational const &q ); // Calculate p/q. Rational div( Rational const &p, Rational const &q ); // Calculate p/n. Rational div( Rational const &p, int const n ); // Calculate n/p. Rational div( int const n, Rational const &p ); // Return the additive inverse -p. Rational negate( Rational const &p ); // Return the multiplicative inverse 1/p. Rational inverse( Rational const &p ); // Return the absolute value of p. Rational abs( Rational const &p ); // Determine whether p == q. bool equal( Rational const &p, Rational const &q ); // Determine whether p == n. bool equal( Rational const &p, int const n ); // Determine whether n == p. bool equal( int const n, Rational const &p ); // Determine whether p != q. bool unequal( Rational const &p, Rational const &q ); // Determine whether p != n. bool unequal( Rational const &p, int const n ); // Determine whether n != p. bool unequal( int const n, Rational const &p ); // Determine whether p < q. bool less_than( Rational const &p, Rational const &q ); // Determine whether p < n. bool less_than( Rational const &p, int const n ); // Determine whether n < p. bool less_than( int const n, Rational const &p ); // Determine whether p <= q. bool less_than_or_equal( Rational const &p, Rational const &q ); // Determine whether p <= n. bool less_than_or_equal( Rational const &p, int const n ); // Determine whether n <= p. bool less_than_or_equal( int const n, Rational const &p ); // Determine whether p >= q. bool greater_than_or_equal( Rational const &p, Rational const &q ); // Determine whether p >= n. bool greater_than_or_equal( Rational const &p, int const n ); // Determine whether n >= p. bool greater_than_or_equal( int const n, Rational const &p ); // Determine whether p > q. bool greater_than( Rational const &p, Rational const &q ); // Determine whether p > n. bool greater_than( Rational const &p, int const n ); // Determine whether n > p. bool greater_than( int const n, Rational const &p ); // Return a floating-point approximation of p. double real( Rational const &p ); // Return a string representation of p. std::string to_string( Rational const &p ); /////////////////////// // Class definition // /////////////////////// // Store the numerator and denominator of a rational number. class Rational { public: int numer_; int denom_; };