Menu

[Solved]Tortoise Vs Hare Race C Program Must Done C Use Pointers Q37290849

Tortoise vs. Hare Race – C Program –

Must be done in C,

Use pointers:

Steps: In this Race.c, youll recreate one of the truly great moments in history, namely the classic race of the tortoise and

Sample run ON YOUR MARK, GET SET BANG AND THEY RE OFF H T T H Hare wins. Yuch ON YOUR MARK, GET SET BANG AND THEY RE OFF TORT

Steps: In this Race.c, you’ll recreate 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 squae 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 program should adjust the position of the animals according to the rules: Animal Move T Tortoise Fast plod Percentage of the timeActual Move 50% 20% 30% 20% 20% 10% 30% 20% 3 squares to the right 6 squares to the left 1 square to the right No move at all 9 squares to the right 12 squares to the left Slow plod Hare Big hop re to the right ma Small sli 2 squares to the left Functions Use variables to keep track of the positions of the animals (i.e., position numbers are 1-70). Start each animal at position 1 (ie., 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 s i s 5, a “slip” when 6 <i < 7, or a slow plod” when 8 s i s 10 Use a similar technique to move the hare Begin the race by printing Then, for each tick of the clock (ie., each repetition of a loop), print a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land on the same square. In this case, the tortoise bites the hare and your program 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, then print the winner and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print Hare wins. Yuch 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 Ifneither animal wins, perform the loop again to simulate the next tick of the clock. Use function sleep()from <time.h> to slow down the game and feel the excitement! Sample run ON YOUR MARK, GET SET BANG AND THEY RE OFF H T T H Hare wins. Yuch ON YOUR MARK, GET SET BANG AND THEY RE OFF TORTOISE WINS!! YAY!!! ON YOUR MARK, GET SET BANG AND THEY RE OFF T H T H TH OUCH! !! OUCH! !! H T H T Hare wins. Yuch. Show transcribed image text Steps: In this Race.c, you’ll recreate 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 squae 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 program should adjust the position of the animals according to the rules: Animal Move T Tortoise Fast plod Percentage of the timeActual Move 50% 20% 30% 20% 20% 10% 30% 20% 3 squares to the right 6 squares to the left 1 square to the right No move at all 9 squares to the right 12 squares to the left Slow plod Hare Big hop re to the right ma Small sli 2 squares to the left Functions Use variables to keep track of the positions of the animals (i.e., position numbers are 1-70). Start each animal at position 1 (ie., 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

Expert Answer


Answer to Tortoise vs. Hare Race – C Program – Must be done in C, Use pointers: … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *