Programmer's Corner Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programmer's Corner - Forums


Pointers/ help Please

 
Post new topic   Reply to topic    Programmer's Corner Forum Index -> C / C++
Author Message
diivne
Guest





PostPosted: Mon May 08, 2006 9:54 pm    Post subject: Pointers/ help Please Reply with quote

Please read this carefully.


(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.

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 on per second. With each tick of the clock, your program should adjust the position of the animals according to the rules;

Tortoise:
Fast plod 50%
3 squares to the right;
Slip 20% 6 squares to the right;
Slow plod 30% 1 square to the right;

Hare:
Sleep 20% No moves at all;
Big hop 20% 9 squares to the right;
Big slip 10% 12 squares to the left;
Small hop 30% 1 square to the right;
Small slip 20% 2 squares to the left;

Use variables to keep track of the positions of the animal( 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 similar technique to move hare.

Begin the race by printing

BANG!!!!!!
AND THEY’RE OFF!!!!!

Then, for each tick of the clock (i.e,. 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 if either animal has reach 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. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you are ready to run your program assemble a group of fans to watch the race.







--------------------------------------------------------------------------------
Back to top
theraje
Cap'n Arr!


Joined: 22 Oct 2004
Posts: 262

PostPosted: Tue May 09, 2006 9:38 am    Post subject: Reply with quote

If you are looking for some help, please tell us which part of the program you are having trouble with.

If you are looking for someone to do your homework for you, look elsewhere.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Programmer's Corner Forum Index -> C / C++ All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2002 phpBB Group