home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch12 / fractst.cpp < prev    next >
C/C++ Source or Header  |  2005-06-16  |  804b  |  29 lines

  1. //             fractst.cpp
  2. //
  3. // Synopsis  - Instantiates and displays three Fraction objects. 
  4. //             Then the results of the Fraction unary - and 
  5. //             Fraction addition are calculated and displayed.
  6. //
  7. // Objective - To demonstrate the Fraction class and
  8. //             the overloading of operators for a 
  9. //             Fraction object.
  10.  
  11. // Include Files
  12. #include <iostream.h>
  13. #include "fraction.h"
  14.  
  15. int main()
  16. {
  17.     Fraction f1(4, 5), f2(4, -3), f3;
  18.  
  19.     cout << f1 << endl;                              // Note 1
  20.     cout << f2 << endl;
  21.     cout << f3 << endl;
  22.  
  23.     f3 = -f1;                                        // Note 2
  24.     cout << f3 << endl;
  25.  
  26.     f3 = f1 + f2;                                    // Note 3
  27.     cout << f3 << endl;
  28.     return 0;
  29. }