Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c + + Programming Assignment Content 8 . 1 2 ( Simulation: The Tortoise and the Hare ) In this exercise, you'll re - create
cProgramming Assignment Content
Simulation: The Tortoise and the Hare In this exercise, you'll recreate the classic race of the tortoise and the hare.
You'll use randomnumber generation to develop a simulation of this memorable event.
Our contenders begin the race at "square of squares. Each square represents a possible position along the race course. The
finish line is at square The first contender to reach or pass square 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 is a clock that ticks once per second. With each tick of the clock, your program should use
function moveTortoise and moveHare to adjust the position of the animals according to the rules in Fig. view your book for
the rules in the table These functions should use pointerbased passbyreference to modify the position of the tortoise
and the hare.
Use variables to keep track of the positions of the animals ie position numbers are Start each animal at position ie the
"starting gate" If an animal slips left before square move the animal back to square
Generate the percentages in Fig. by producing a random integer in the range For the tortoise, perform a "fast plod"
when a "slip" when or a "slow plod" when Use a similar technique to move the hare.
Begin the race by displaying
BANG
AND THEY'RE OFF
For each tick of the clock ie each iteration of a loop display a position line showing the letter in the tortoise's position and
the letter in the hare's position. Occasionally, the contenders land on the same square. In this case, the tortoise bites the hare and
your program should display OUCH!!! beginning at that position. All positions other than the T the H or the OUCH!!! in case of a tie
should be blank.
After displaying each line, test whether either animal has reached or passed square If so display the winner and terminate the
simulation. If the tortoise wins, display TORTOISE WINS!!! YAY!!! If the hare wins, display Hare wins. Yuch. If both animals win on the
same clock tick, you may want to favor the tortoise the "underdog" or you may want to display It's a tie. If neither animal wins,
perform the loop again to simulate the next tick of the clock.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started