home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / Contain.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  990 b   |  48 lines

  1. // CONTAIN.CPP
  2. // C++ program that illustrates contained classes
  3.  
  4. #include <iostream.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7.  
  8. const int MIN = 1;
  9. const int MAX = 1000;
  10. const double PI = 4 * atan(1);
  11. const double INIT_SEED = 13.0;
  12.  
  13. class Random        // class to be contained within Guess class
  14. {
  15.   public:
  16.     Random(double fSeed = INIT_SEED)
  17.       { m_fSeed = fSeed; }
  18.     double getRandom();
  19.  
  20.   protected:
  21.     double m_fSeed;
  22.  
  23.     double fract(double x);
  24.     double cube(double x);
  25. };
  26.  
  27. class Guess          // class that will contain Random
  28. {
  29.   public:
  30.     void play();
  31.  
  32.   protected:
  33.     int m_nSecretNum;
  34.     int m_nNumber;
  35.     int m_nIter;
  36.     int m_nMaxIter;
  37.     Random m_Rnd;    // declares m_Rnd as an instance of Random
  38.                      // therefore Random is referred to as a
  39.                      // contained class
  40.  
  41.     void initGame();
  42.     void getFirstGuess();
  43.     void getGuess();
  44.     int playMore();
  45.     void endGame();
  46.  
  47. };
  48.