Rational numbers ================ This example introduces a simple class representing rational numbers and a collection of functions that perform arithmetic and comparisons on rational numbers. Files ===== Rational.hpp Contains the declaration and definition of the Rational class, together with the declarations of all functions that operate on Rational objects. Rational.cpp Contains the definitions of the functions declared in Rational.hpp. main.cpp Contains examples demonstrating how to create Rational objects and call the functions that operate on them. The Rational class ================== A Rational object stores two integers: numer_ denom_ These represent the numerator and denominator of a rational number. For example, Rational p{ 3, 4 }; represents the rational number 3/4. Functions are provided for operations including: - addition, - subtraction, - multiplication, - division, - additive inverses, - multiplicative inverses, - absolute values, - comparisons, - floating-point approximations, and - conversion to a string. Many of the functions are overloaded so that rational numbers can also be used with integers. For example, add( p, q ) add( p, 2 ) add( 2, q ) call three different functions with the same identifier. Important limitations ===================== This is a deliberately simple implementation intended to demonstrate classes and functions. Rational numbers are not automatically reduced to lowest terms. Thus, for example, 2/4 may be stored as 2/4 rather than 1/2. The comparison functions nevertheless compare the values of the rational numbers rather than simply comparing their stored numerators and denominators. A valid Rational object must have a non-zero denominator. At this stage, the class itself does not prevent a programmer from creating an invalid object such as Rational p{ 3, 0 }; Later, constructors can be used to enforce requirements such as this when an object is created. Purpose ======= This example demonstrates classes, function overloading, const references, assertions, and the reuse of existing functions when implementing related operations. Later, these operations could be implemented using member functions and overloaded operators so that rational-number expressions more closely resemble ordinary mathematical notation. Compiling ========= Compile both main.cpp and Rational.cpp. For example: g++ -std=c++17 -Wall -Wextra -pedantic main.cpp Rational.cpp