Source of arrtime.cpp


  1: // Filenme: ARRTIME.CPP
  2: // Purpose: Illustrates an array of (Time) objects.

  4: #include <iostream>
  5: #include <fstream>
  6: #include <iomanip>
  7: using namespace std;


 10: #include "TIME4.H"


 13: int main()
 14: {
 15:     cout << "\nThis program illustrates an array "
 16:          << "of Time objects. "                       << endl
 17:          << "You should study the source code "
 18:          << "at the same time as the output. "        << endl << endl;

 20:     Time t0;
 21:     Time t1(12);
 22:     Time t2(11, 45);
 23:     Time t3(11, 44, 55);

 25:     ofstream outFile("times.tmp");

 27:     outFile << t0 << endl
 28:             << t1 << endl
 29:             << t2 << endl
 30:             << t3 << endl;

 32:     outFile.close();


 35:     // Each Time object in the following array declaration is
 36:     // initialized using the default constructor for the Time class.
 37:     Time t[4];

 39:     int i;
 40:     for (i = 0; i < 4; i++)   // Display the values to prove they are the
 41:         cout << t[i] << endl; // ones supplied by the default constructor.
 42:     cout << endl;

 44:     ifstream inFile("times.tmp");

 46:     Time timeRead;
 47:     int index = 0;
 48:     while (inFile >> timeRead)
 49:         t[index++] = timeRead;

 51:     for (i = 0; i < index; i++)
 52:         cout << t[i] << endl;

 54:     inFile.close();

 56:     return 0;
 57: }