home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX1124.CPP
- // main program to exercise I/O facilities in Fraction class
- // This version shows input and output operators as member
- // functions rather than friends.
- //---------------------------------------------------------------
-
- // files in this example:
- // %F,15,EX11241.H%EX11241.H definition of the class Fraction
- // %F,15,EX11241.CPP%EX11241.CPP member functions of the class Fraction
- // EX1124.CPP this file
- //-------------------------------------------------------------
-
- #include "EX11241.H"
- #include <iostream.h>
-
- //-------------------------------------------------------------
- const int nfrac = 4; // 4 fraction objects
-
- //--------------------------------------------------------------
-
- void main()
- { Fraction f[nfrac]; // in array for convenience
- // user input values for Fraction objects
- int i;
- cout << "Enter 4 fractions (e.g. 1/2 -4/6 3 8/5 ): ";
- for ( i = 0; i < nfrac; i++)
- f[i] >> cin; // overloaded >>
- // echo these values
- for ( i = 0; i < nfrac; i++) {
- cout << " Here is fraction " << i << ": ";
- f[i] << cout;
- cout << endl;
- }
- // prompt to return to tutorial
- cout << "Press any key to return to tutorial." << endl;
- }
-
- //---------------------------------------------------------------
-