ENGINEERING GRAPHICS H167

           DAILY ASSIGNMENT D21 (Advanced)

 

Because of the precision issues with floating point numbers in computers, it is often favorable to store rational numbers as separate numerators and denominators, especially in the case of repeating decimals.

 

Your job is to implement a Rational class that will work with the following code. You are not required to build a class to meet the optional statements in the code. Ambitious students are encouraged to try to implement a class for the optional parts. Those students who choose not to implement the optional parts can omit them from their main code.

 

Rationals should be stored in REDUCED FORM at ALL TIMES.

 

void main()

{

 

    Rational number1;                   // Rational retains default values

    Rational number2( 67 );             // Integer provided as numerator

    Rational number3( 999, 2997 );      // Integers provided as numerator and denominator

    Rational number4( 350.33 );         // OPTIONAL: Rational converted from decimal form

    Rational number5( 256.9, 385.76 );  // OPTIONAL: Rational numerator and

                                        //           denominator converted from decimal form

 

    /*** Display numbers using output accessor method ***/

    cout << "number1 = ";

    number1.output();

    cout << '\n';

   

    cout << "number2 = ";

    number2.output();

    cout << '\n';

  

    cout << "number3 = ";

    number3.output();

    cout << '\n';

 

    cout << "number4 = ";       // number4 is

    number4.output();           // OPTIONAL

    cout << '\n';

  

    cout << "number5 = ";       // number5 is

    number5.output();           // OPTIONAL

    cout << '\n';

 

    /*** OPTIONAL: Display numbers by using ostreams ***/

    cout << "number1 = " << number1 << '\n';

    cout << "number2 = " << number2 << '\n';

    cout << "number3 = " << number3 << '\n';

    cout << "number4 = " << number4 << '\n';

    cout << "number5 = " << number5 << '\n';

 

    /*** Do various arithmetic on numbers with Rationals and ints ***/

    number1 = number2 * number3;

    number3 = number2 + 532;

    number2 = number2 / 35;

 

    /*** OPTIONAL: Implement other operators ***/

    number4++;

    number5‑‑;

    number4 += ++number4 ‑ 53.6;

 

    /*** Display numbers using one of the methods above ***/

    cout << "number1 = " << number1 << '\n';

    cout << "number2 = " << number2 << '\n';

    cout << "number3 = " << number3 << '\n';

    cout << "number4 = " << number4 << '\n';                // number4 is OPTIONAL

    cout << "number5 = " << number5 << '\n';                // number5 is OPTIONAL

 

}

 

 

Name________________________ Instr. ____________ Room______ Seat_____Hour_____