walko.h From Astrachan p. 326-327 ---------------------------------- #ifndef _RANDOMWALKO_H #define _RANDOMWALKO_H // Owen Astrachan, 6/20/96 // class for implementing a one dimensional random walk with observer // // constructor specifies observer and number of steps to take, random walk // goes left or right with equal probability, updating the observer // with each step // // two methods for running simulation: // // void Simulate() -- run a complete simulation // // First(); ! IsDone(); Next() -- idiom for starting and iterating // one step at a time // // accessor functions: // // int GetPosition() -- returns x coordinate // (# steps left/right from origin) // // int GetSteps() -- returns total # steps taken #include "observer.h" class RandomWalkO { public: RandomWalkO(WalkObserver & obs, int maxSteps); // constructor, set observer and max steps void First(); // take first step of walk bool IsDone(); // returns true if walk finished, else false void Next(); // take next step of random walk void Simulate(); // take all steps in simulation int GetPosition(); // returns position (x coord) of frog int GetSteps(); // returns # of steps taken by frog private: void TakeStep(); // simulate one step of walk int myPosition; // current x coordinate int mySteps; // # of steps taken int myMaxSteps; // maximum # of steps allowed WalkObserver& myObserver; // observe this walk }; #endif