Bridge Walk

In this problem a person is placed at the center of a 7 meter long bridge. Each step, the person moves 1 meter either forward or backward at random.

  1. Write a program that determines how many steps the person will walk before taking a step off the bridge. Have the program average 50 trials and report the average and greatest number of steps. Your C++ program should use top-down design and functions to solve the problem.
  2. Display the position of the person on the bridge at each stage of one bridge walk

    For example,

    	Step 0:	 |---*---|
    	Step 1:	 |--*----|
    	Step 2:	 |-*-----|
    	Step 3:	 |--*----|
    	   . . . 

  3. Print a table of bridge length vs. average number of steps taken to get off.
    Use 50 trials for each bridge length and try odd lengths from 5 to 21 meters long.
    For example,
    	        Length		        Average Number of Steps 
    		5			5.6
    		7			7.2
    		9			8.0
    		...			...
    		21			37.5
    What is the relationship between the length of the bridge and the average number of steps taken to get off?

Continue to:  Unit 1  / Prev  / Next