17.2  Case Study: Fractional Numbers

New type to represent a ratio of 2 integers:

Fraction a( 3, 4 ); // Represents 3/4
Fraction b( 7 ); // Represents 7/1

Fractions should behave as other numbers:

Fraction c( 1, 2 );
   if( a < b )
      c = b - a;
   else
      c = a - b;
   cout << "Value is " << c << "\n";

prev |top |next