home *** CD-ROM | disk | FTP | other *** search
- // CONTAIN.CPP
- // C++ program that illustrates contained classes
-
- #include <iostream.h>
- #include <stdlib.h>
- #include <math.h>
-
- const int MIN = 1;
- const int MAX = 1000;
- const double PI = 4 * atan(1);
- const double INIT_SEED = 13.0;
-
- class Random // class to be contained within Guess class
- {
- public:
- Random(double fSeed = INIT_SEED)
- { m_fSeed = fSeed; }
- double getRandom();
-
- protected:
- double m_fSeed;
-
- double fract(double x);
- double cube(double x);
- };
-
- class Guess // class that will contain Random
- {
- public:
- void play();
-
- protected:
- int m_nSecretNum;
- int m_nNumber;
- int m_nIter;
- int m_nMaxIter;
- Random m_Rnd; // declares m_Rnd as an instance of Random
- // therefore Random is referred to as a
- // contained class
-
- void initGame();
- void getFirstGuess();
- void getGuess();
- int playMore();
- void endGame();
-
- };
-