home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX0902.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-20  |  950 b   |  37 lines

  1. // \EXAMPLES\EX0902.CPP
  2.  
  3. //---------------------------------------------------------
  4. // files in this example:
  5. // %F,15,EX0900.H%EX0900.H      definition of Fraction class
  6. // %F,15,EX0900.CPP%EX0900.CPP    Fraction members & friends
  7. // EX0902.CPP    this file
  8. //---------------------------------------------------------
  9.  
  10. #include <iostream.h>
  11. #include "EX0900.H"
  12.  
  13. void main()
  14. {
  15.    Fraction y, a(1.5), b(3.0);   // create three fractions
  16.    y = a + b;                    // add two fractions
  17.    cout << "1.5 + 3.0 = ";
  18.    cout << y;
  19.    cout << endl;
  20.  
  21.    y = b - a;                    // subtract two fractions
  22.    cout << "3.0 - 1.5 = ";
  23.    cout << y;
  24.    cout << endl;
  25.  
  26.    y = a * a;                    // multiply two fractions
  27.    cout << "1.5 * 1.5 = ";
  28.    cout << y;
  29.    cout << endl;
  30.  
  31.    y = b / a;                   // divide one fraction by another
  32.    cout << "3.0 / 1.5 = ";
  33.    cout << y;
  34.    cout << endl;
  35.  
  36. }
  37.