home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / CLASSEXM.ZIP / QUEUETST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  2.3 KB  |  101 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3.  
  4. // Contents -----------------------------------------------------------------
  5. //
  6. //      main
  7. //
  8. // Description
  9. //
  10. //      Contains a simple example program for class Queue.
  11. //
  12. // End ---------------------------------------------------------------------
  13.  
  14. // Interface Dependencies ---------------------------------------------------
  15.  
  16. // None
  17.  
  18. // End Interface Dependencies ------------------------------------------------
  19.  
  20. // Implementation Dependencies ----------------------------------------------
  21.  
  22. #ifndef __IOSTREAM_H
  23. #include <iostream.h>
  24. #define __IOSTREAM_H
  25. #endif
  26.  
  27. #ifndef __DOS_H
  28. #include <dos.h>
  29. #define __DOS_H
  30. #endif
  31.  
  32. #ifndef __STDLIB_H
  33. #include <stdlib.h>
  34. #define __STDLIB_H
  35. #endif
  36.  
  37. #ifndef __LTIME_H
  38. #include <ltime.h>
  39. #endif
  40.  
  41. #ifndef __QUEUE_H
  42. #include <queue.h>
  43. #endif
  44.  
  45. // End Implementation Dependencies -------------------------------------------
  46.  
  47.  
  48. // Function //
  49.  
  50. int main()
  51.  
  52. // Summary -----------------------------------------------------------------
  53. //
  54. //      Illustrates a use of the Queue class.  Saves
  55. //      the current time in a queue, then waits for a random length of
  56. //      time before saving the current time in a queue.  After 7 samplings
  57. //      have been entered in the queue, the queue is printed.
  58. //
  59. //      Usage:  queuetst
  60. //
  61. // Return Value
  62. //
  63. //      noError
  64. //
  65. //      Returns a 0 if no error occurs during execution, a 1 otherwise.
  66. //
  67. // End ---------------------------------------------------------------------
  68. {
  69.     Queue timeLine;
  70.  
  71.     cout << "\nSampling";
  72.     for ( int i = 0; i < 7; i++ )
  73.     {
  74.         struct time snapShot;
  75.         gettime( &snapShot );
  76.         Time sample( snapShot.ti_hour,
  77.                      snapShot.ti_min,
  78.                      snapShot.ti_sec,
  79.                      snapShot.ti_hund );
  80.  
  81.         timeLine.put ( *(new Time( sample )) );
  82.         cout << ".";
  83.         delay( rand() % 5000 );
  84.     }
  85.  
  86.     cout << "\nThe timing samples are:\n\n";
  87.  
  88.     while( !timeLine.isEmpty() )
  89.         {
  90.         Time& sampleTime = (Time&)timeLine.get();
  91.         cout << sampleTime << "\n";
  92.         delete &sampleTime;
  93.         } // end for all element in the queue.
  94.  
  95.     return 0;
  96. }
  97. // End Function main //
  98.  
  99.  
  100. 
  101.