Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Pointers Lab Have you heard or read the story of The Tortoise and the Hare? You can watch Walt Disneys rendition here: https://youtu.be/ MeZe2qPLPh0

C++ Pointers Lab

Have you heard or read the story of The Tortoise and the Hare?

You can watch Walt Disneys rendition here:

https://youtu.be/

MeZe2qPLPh0

or you can read the story here:

http://read.gov/

aesop/025.html

.

Now that you are familiar with the story, lets code an algorithm

for a simulation!

(Simulation: The Tortoise and the Hare) In this exercise, youll re-

create the classic race of the tortoise and the hare. Youll 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

following rules:

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

170). 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 THEYRE 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 tortoises

position and the letter H in the hares

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 Its

a tie. If neither animal wins, perform the

loop again to simulate the next tick of the

clock.

To the right is a screenshot example of

what your output may look like

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions