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

  1. // \EXAMPLES\EX1124.CPP
  2. //  main program to exercise I/O facilities in Fraction class
  3. //  This version shows input and output operators as member
  4. //  functions rather than friends.
  5. //---------------------------------------------------------------
  6.  
  7. //  files in this example:
  8. // %F,15,EX11241.H%EX11241.H     definition of the class Fraction
  9. // %F,15,EX11241.CPP%EX11241.CPP member functions of the class Fraction
  10. // EX1124.CPP      this file
  11. //-------------------------------------------------------------
  12.  
  13. #include "EX11241.H"
  14. #include <iostream.h>
  15.  
  16. //-------------------------------------------------------------
  17. const int nfrac = 4;                // 4 fraction objects
  18.  
  19. //--------------------------------------------------------------
  20.  
  21. void main()
  22. {  Fraction f[nfrac];               // in array for convenience
  23. // user input values for Fraction objects
  24.   int i;
  25.   cout << "Enter 4 fractions (e.g.  1/2  -4/6  3  8/5 ):  ";
  26.   for ( i = 0; i < nfrac; i++)
  27.      f[i] >> cin;                         // overloaded >>
  28. // echo these values
  29.   for ( i = 0; i < nfrac; i++) {
  30.      cout << " Here is fraction " << i << ": ";
  31.      f[i] << cout;
  32.      cout << endl;
  33.   }
  34. // prompt to return to tutorial
  35.   cout << "Press any key to return to tutorial." << endl;
  36. }
  37.  
  38. //---------------------------------------------------------------
  39.