CPS 100E: Groupwork # 2:
Tracking the Wily Random Walker


Write Group Member Names in the space below










Overview

Form groups of size 3-4 persons. DO NOT WORK ALONE. Start this group activity by introducing each member of the group. One group member should be the scribe, this person is responsible for recording the group's endeavors. You'll need to turn in a writeup for the group activity, the scribe is responsible for writing each group member's name on the writeup.

You'll work some on modifying a simple random walk program related to the lab done on Thursday, September 12 (Lab 2).


Tracking Locations

Add a vector and modify the code below so that the number of times the walker visits every location is kept and printed when the simulation is over. As a first step, just track how many times each location in the range [-100..100] are visited. #include <iostream.h> #include "dice.h" #include "prompt.h" // simulate one-dimensional random walk // Owen Astrachan, 8/13/94 int main() { int numSteps = PromptRange("enter # of steps",0,1000000); int position = 0; // "frog" starts at position 0 Dice die(2); // used for "coin flipping" int k; for(k=0; k < numSteps; k++) { switch (die.Roll()) { case 1: position += 1; // step to the right break; case 2: position -= 1; // step to the left break; } } cout << "final position = " << position << endl; return 0; }