Tortoise_Hare_Race_Simulation_CPP

Download Category:

Tortoise_Hare_Race_Simulation_CPP.zip - (8.39 MB)
[
Tortoise_Hare_Race_Simulation_CPP/Debug/
Tortoise_Hare_Race_Simulation_CPP/Debug/cl.command.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/CL.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/CL.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.4092.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.4092.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.4092-cvtres.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.4092-cvtres.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.command.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link-cvtres.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/link-cvtres.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/mt.command.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/mt.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/mt.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/rc.command.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/rc.read.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/rc.write.1.tlog
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.exe
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.exe.embed.manifest
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.exe.embed.manifest.res
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.exe.intermediate.manifest
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.ilk
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.lastbuildstate
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.log
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.obj
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP.pdb
Tortoise_Hare_Race_Simulation_CPP/Debug/Tortoise_Hare_Race_Simulation_CPP_manifest.rc
Tortoise_Hare_Race_Simulation_CPP/Debug/vc100.idb
Tortoise_Hare_Race_Simulation_CPP/Debug/vc100.pdb
Tortoise_Hare_Race_Simulation_CPP/ipch/
Tortoise_Hare_Race_Simulation_CPP/ipch/tortoise_hare_race_simulation_cpp-65e368de/
Tortoise_Hare_Race_Simulation_CPP/ipch/tortoise_hare_race_simulation_cpp-65e368de/tortoise_hare_race_simulation_cpp-2c2061a4.ipch
Tortoise_Hare_Race_Simulation_CPP/Question.txt
Tortoise_Hare_Race_Simulation_CPP/Screenshot_1.png
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.cpp
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.sdf
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.sln
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.suo
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.vcxproj
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.vcxproj.filters
Tortoise_Hare_Race_Simulation_CPP/Tortoise_Hare_Race_Simulation_CPP.vcxproj.user
]

In this exercise, you’ll re-create 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 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. 8.18. These functions should use pointer-based pass-by-reference to modify the position of the tortoise and the hare.
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 the preceding table 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 or a “slow plod” when 8 = i =10. Use a similar technique to move the hare.
Begin the race by displaying
BANG !!!!!
AND THEY’RE OFF !!!!!

For each tick of the clock (i.e., each repetition of a loop), display a 70-position line showing the letter T in the tortoise’s position and the letter H 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 70. 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.

Write a Review

Get a fresh solution of this question. Ask it now to our experts.
doubt

Ask Your Question

We have verified professionals who are ready to answer your question.

time

Save Time and Money

We choose experts who can quickly answer your question and that suit your budget.

download

Get Your Answer

Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.