Question

In: Computer Science

Question 17- Chapter 10 (Internet and World Wide Web 5th Edition) You will use random number...

Question 17- Chapter 10 (Internet and World Wide Web 5th Edition)

You will use random number generation to develop a simulation for the classic race of the tortoise and the hare. The 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. Assume that there is a clock that ticks once per second. With each tick of the clock, your script should adjust the position of the animals according to the rules in Table 1 below:

Animal Move type Percentage of time Actual move Tortoise Fast plod 50% 3 squares to the right Slip 20% 6 squares to the left Slow plod 30% 1 square to the right Hare Sleep 20% No move 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 animals (i.e., position numbers are 1 – 70). Start each animal at position 1. If an animal slips left before square 1, move the animal back to square 1. Generate the percentages in Table 1 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, and a “slow plod” when 8 ≤ i ≤ 10. Use a similar technique to move the hare. Provide a button labeled “Start Race”, on which the user clicks to start the race. Begin the race by printing: ON YOUR MARK, GET SET 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 script should print OUCH!!! at that position. All print positions other than the T, the H, or the OUCH!!! should be blank. After each line is printed, test whether either animal has reached or passed square 70. If so, print the winner and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print HARE WINS. YUCK! If both animals win on the same tick, print IT’S A TIE. Also, print the time elapsed (the number of ticks) of the race. If neither animal wins, perform the loop again to simulate the next tick of the clock. Separate your script (.js file) and your CSS rules (.css file – if any) from the HTML5 file. Note: Later in the book, we introduce a number of Dynamic HTML capabilities, such as graphics, images, animation and sound. As you study those features, you may enjoy enhancing your tortoise-and-hare contest simulation. [

Solutions

Expert Solution

Here is the code for the given scenario:

#include <stdlib.h>

#include<stdio.h>

#include <time.h>

int main(){

const int FINISH = 70;

int i;

int hare = 0;

int tortoise = 0;

int t;

int h;

printf("The race between the Tortiose and the Hare!\nOn your mark, get set, Bang !!!\n");

printf("And they are off!\n");

//move untill either contender finish the race

while(tortoise < FINISH && hare < FINISH) {

srand(time(NULL));

i=rand()%10 +1;

//Moving the tortiose

if(i >= 8)

tortoise += 1;

else if (i >=6)

tortoise -= 6;

else if(i>=1)

tortoise += 3;

//Moving the hare

if (i >= 8)

hare += 1;

else if (i>= 6)

hare = hare;

else if(i >= 4)

hare += 9;

else if (i== 3)

hare -= 12;

else if (i >= 1)

hare -= 2;

//When the tortise and hare are on the same space.

else if(hare == tortoise){

int k;

for(k = 0; k < hare-1; k++){

printf(" ");

}

printf("Ouch!");

}

//status of the race

for( i = 0; i <= 70; i++){

if(i == hare){

printf("H");

}

else if (i == tortoise){

printf("T");

}

else{

printf("-");

printf("\n");

}

}

}

// Which one wins

if( hare >= 70){

printf("Hare wins. Yuch.\n");

}

if(tortoise >= 70){

printf("\nTORTOISE WINS!!! YAY\n!!!");

}

if (hare >= 70 && tortoise >= 70){

printf("It's a tie.\n");

}

return 0;

}


Related Solutions

Use HTML5 to create a document that contains the following text: Internet and World Wide Web...
Use HTML5 to create a document that contains the following text: Internet and World Wide Web How to Program: Fifth Edition Welcome to the world of Internet programming. We have provided coverage for many Internet-related topics. Use h1 for the title (the first line of text), p for text (the second and third lines of text). Insert a horizontal rule between the h1 element and the p element. Open your new document in a web browser to view the marked-up...
How is network data delivered on the Internet versus the World Wide Web?
How is network data delivered on the Internet versus the World Wide Web?
Java Programming 5th edition Chapter 10 Inheritance Programs Part 1 Number 3 on page 719 which...
Java Programming 5th edition Chapter 10 Inheritance Programs Part 1 Number 3 on page 719 which creates a Point class with 2 instance variables; the xCoordinate and yCoordinate. It should have a default constructor and a values constructor. Also include a set method that sets both attributes, a get method for each attribute, and a method that redefines toString() to print the attributes as follows. point: (x, y) Part 2 Do number 4 on page 719 which creates a Circle...
Define the following terms related to the Internet: TCP/IP, RFC, the World Wide Web, Internet Governance,...
Define the following terms related to the Internet: TCP/IP, RFC, the World Wide Web, Internet Governance, ISOC, W3C, IT‐ISAC, Internet and WWW Technology.
QUESTION a. Explore the Web for the latest World Internet Users Population Stats for 2019 comparing...
QUESTION a. Explore the Web for the latest World Internet Users Population Stats for 2019 comparing at least 4 world regions (for example: Africa, Asia, Europe, Middle East) in terms of Internet users distribution % and penetration rate (% population). b. Apply Porter’s Five Forces analytical framework to the Internet. Your answer should include critical elements supported with evidence/ justification.
Answer the Following Question using Web: a) Use web search to identify and name 10 university...
Answer the Following Question using Web: a) Use web search to identify and name 10 university groups in USA and Canada with research programs in the area of VLSI design. Pick two research groups of your choice. b)Use web search to find open source libraries for VLSI design components. List the type of designs available there. Give description of one design you find in these libraries. NOTE: Can You please explain with details, thank You.
Cognitive Psychology: Applying The Science of the Mind (4th Edition) Chapter 10 Discussion Question: What do...
Cognitive Psychology: Applying The Science of the Mind (4th Edition) Chapter 10 Discussion Question: What do you think is the most important factor in communicating through your writing? Think of the comments you get from professors, or the problems you seem to have in writing. Do they map onto any of the factors you've read about? Here's an example of one of my classmate response.... I feel that with writing being such a common way of communicating it is important...
Answer the following question thank You •Q1: Use web search to identify and name 10 university...
Answer the following question thank You •Q1: Use web search to identify and name 10 university groups in USA and Canada with research programs in the area of VLSI design. Pick two research groups of your choice.
Review and discussion question Number 4 page 21 on Supervision: Concepts and Skill Building Edition 10...
Review and discussion question Number 4 page 21 on Supervision: Concepts and Skill Building Edition 10 .....Chapter 1 What are some advantages of greater diversity?
Chapter 17 - Question 6 : I figure out the answers, could you check and let...
Chapter 17 - Question 6 : I figure out the answers, could you check and let me know what wrong (if any). Thank you Miguel receives tangible personal property as an inheritance in 2016. The property was depreciated by the deceased (Miguel's father), and Miguel will also depreciate it. At the date of the deceased's death, the property was worth $532,000. The deceased had purchased it for $900,000 and had taken $523,000 of depreciation on the property. Miguel takes $223,000...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT