((Simulation: The Tortoise and the Hare) In this problem, you’ll re-create one of the truly great moments in history, namely the classic race of the tortoise and the hare. You’ll use random number generation to develop a simulation of this memorable event. Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground. Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70). Start each animal at position 1 (i.e., the “starting gate”). If an animal slips left before square 1, move the animal back to square 1. Generate the percentages in Fig. 10.24 by producing a random integer i in the range 1 ≤i ≤10. For the tortoise, perform a “fast plod” when 1 ≤i ≤5, a “slip” when 6 ≤i ≤7 and a “slow plod” when 8 ≤i ≤10. Use a similar technique to move the hare. Begin the race by printing BANG !!!!! AND THEY'RE OFF !!!!! Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show- ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa- sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your script should print OUCH!!! beginning at that position. All print positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank. After each line is printed, test whether either animal has reached or passed square 70. If so, print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may want to favor the turtle (the “underdog”), or you may want to print It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you’re ready to run your script, assemble a group of fans to watch the race. You’ll be amazed at how involved your audience gets!

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.3: Interactive While Loops
Problem 6E: (Conversion) a. Write a C++ program to convert meters to feet. The program should request the...
icon
Related questions
Question

((Simulation: The Tortoise and the Hare) In this problem, you’ll re-create one of the truly great moments in history, namely the classic race of the tortoise and the hare. You’ll use random number generation to develop a simulation of this memorable event.

Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground.

Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70). Start each animal at position 1 (i.e., the “starting gate”). If an animal slips left before square 1, move the animal back to square 1.

Generate the percentages in Fig. 10.24 by producing a random integer i in the range 1 ≤i ≤10. For the tortoise, perform a “fast plod” when 1 ≤i ≤5, a “slip” when 6 ≤i ≤7 and a “slow plod” when 8 ≤i ≤10. Use a similar technique to move the hare.

Begin the race by printing

BANG !!!!! AND THEY'RE OFF !!!!!

Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show- ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa- sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your script should print OUCH!!! beginning at that position. All print positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank.

After each line is printed, test whether either animal has reached or passed square 70. If so, print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may want to favor the turtle (the “underdog”), or you may want to print It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you’re ready to run your script, assemble a group of fans to watch the race. You’ll be amazed at how involved your audience gets!

Animal
Move type
Percentage of the time
Actual move
Sleep
Big hop
Big slip
Small hop
Small slip
Hare
20%
No move at all
20%
9 squares to the right
12 squares to the left
1 square to the right
2 squares to the left
10%
30%
20%
Fig. 10.24 | Rules for adjusting the position of the tortoise and the hare. (Part 2 of 2.)
Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70).
Start each animal at position 1 (i.e., the "starting gate"). If an animal slips left before square 1,
move the animal back to square 1.
Generate the percentages in Fig. 10.24 by producing a random integer i in the range
1sis10. For the tortoise, perform a "fast plod" when 1 Si$5, a "slip" when 6 Si S7 and a "slow
plod" when 8 Si<10. Use a similar technique to move the hare.
Begin the race by printing
BANG !!!!!
AND THEY'RE OFF !!!!!
Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show-
ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa-
sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and
your script should print OUCH!!! beginning at that position. All print positions other than the T,
the H or the OUCH!!! (in case of a tie) should be blank.
After each line is printed, test whether either animal has reached or passed square 70. If so,
print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!!
If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may
want to favor the turtle (the "underdog"), or you may want to print It's a tie. If neither animal
wins, perform the loop again to simulate the next tick of the clock. When you're ready to run your
script, assemble a group of fans to watch the race. You'll be amazed at how involved your audience
gets!
Later in the book, we introduce a number of Dynamic HTML capabilities, such as graphics,
images, animation and sound. As you study those features, you might enjoy enhancing your tor-
toise-and-hare contest simulation.
Transcribed Image Text:Animal Move type Percentage of the time Actual move Sleep Big hop Big slip Small hop Small slip Hare 20% No move at all 20% 9 squares to the right 12 squares to the left 1 square to the right 2 squares to the left 10% 30% 20% Fig. 10.24 | Rules for adjusting the position of the tortoise and the hare. (Part 2 of 2.) Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70). Start each animal at position 1 (i.e., the "starting gate"). If an animal slips left before square 1, move the animal back to square 1. Generate the percentages in Fig. 10.24 by producing a random integer i in the range 1sis10. For the tortoise, perform a "fast plod" when 1 Si$5, a "slip" when 6 Si S7 and a "slow plod" when 8 Si<10. Use a similar technique to move the hare. Begin the race by printing BANG !!!!! AND THEY'RE OFF !!!!! Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show- ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa- sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your script should print OUCH!!! beginning at that position. All print positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank. After each line is printed, test whether either animal has reached or passed square 70. If so, print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may want to favor the turtle (the "underdog"), or you may want to print It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you're ready to run your script, assemble a group of fans to watch the race. You'll be amazed at how involved your audience gets! Later in the book, we introduce a number of Dynamic HTML capabilities, such as graphics, images, animation and sound. As you study those features, you might enjoy enhancing your tor- toise-and-hare contest simulation.
10.17 (Simulation: The Tortoise and the Hare) In this problem, you'll re-create one of the truly
great moments in history, namely the classic race of the tortoise and the hare. You'll use random
number generation to develop a simulation of this memorable event.
Our contenders begin the race at square 1 of 70 squares. Each square represents a possible
position along the race course. The finish line is at square 70. The first contender to reach or pass
square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side
of a slippery mountain, so occasionally the contenders lose ground.
There's a clock that ticks once per second. With each tick of the clock, your script should
adjust the position of the animals according to the rules in Fig. 10.24.
Animal
Move type
Percentage of the time
Actual move
Fast plod
Slip
Slow plod
Tortoise
3 squares to the right
6 squares to the left
50%
20%
30%
1 square to the right
Transcribed Image Text:10.17 (Simulation: The Tortoise and the Hare) In this problem, you'll re-create one of the truly great moments in history, namely the classic race of the tortoise and the hare. You'll use random number generation to develop a simulation of this memorable event. Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground. There's a clock that ticks once per second. With each tick of the clock, your script should adjust the position of the animals according to the rules in Fig. 10.24. Animal Move type Percentage of the time Actual move Fast plod Slip Slow plod Tortoise 3 squares to the right 6 squares to the left 50% 20% 30% 1 square to the right
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Print statement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning