Rational Numbers

  1. Define a class CRational with two data members (numerator and denominator), and two member functions.
  2. Addition: a/b + c/d = (ad+bc)/bd
  3. Reduction (約分) : ac/bc = a/b
  4. Store your definition of class CRational in "rational.h".
  5. Test your class with the following main program:
    
    #include "rational.h"
    
    int main()
    {
       CRational a(1, 4);
       CRational b(3, 4);
       CRational c = a.Addition(b);
       c.Print();
       c.Reduction(); c.Print();
       CRational d = c; d.Print();
       CRational e(c); e.Print();
       return 0;
    }
    
    
  6. If compiled with the -D_DEBUG option, the output may look like
    Constructor(1,4) called
    Constructor(3,4) called
    Copy Constructor(3,4) called
    Constructor(0,1) called
    16/16
    1
    Copy Constructor(1,1) called
    1
    Copy Constructor(1,1) called
    1