تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
c language
Simulation: The Tortoise and the Hare
In this problem, you will recreate one of the truly great moments in history, namely the classic race of the
tortoise and the hare. You will use random number generation to develop a simulation of this memorable
event and use pointers to store/track the position of the two race contestants.
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 adjust the
position of the animals according to the rules shown in the table below.
Implement the "race course" as an integer array containing the numbers from 1 to 70.
• Implement the positions of the tortoise and the hare as pointers, each pointing to the current
location of the tortoise and hare.
Use pointer arithmetic to change pointer locations.
Think of an interesting way of showing the progress of the race on screen.
Animal
Move type
Percentage of the time
Actual move
Tortoise
Fast plod
50%
Slip
20%
Slow plod
30%
Hare
Sleep
20%
Big hop
20%
Big slip
10%
Small hop
30%
3 squares forward
6 squares backward
1 square forward
No move at all
9 squares forward
12 squares backward
1 square forward
Small slip
20%
2 squares backward
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.