walk.h From Astrachan, pp 315-316 ---------------------------------- #ifndef _RANDOMWALK_H #define _RANDOMWALK_H // Owen Astrachan, 6/20/96 // class for implementing a one dimensional random walk // // constructor specifies number of steps to take, random walk // goes left or right with equal probability // // 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 class RandomWalk { public: RandomWalk(int maxSteps); // constructor, parameter = 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 }; #endif