Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following assignment using C: And this is the function that is being referred to in the assignment: double randDouble() { return (double)rand()/((double)RAND_MAX+1); }

Complete the following assignment using C:

And this is the function that is being referred to in the assignment:

double randDouble() { return (double)rand()/((double)RAND_MAX+1); } 

image text in transcribed

image text in transcribed

Random Walk Flavia the fly has landed in the center of a spider web at X=0, Y=0. Luckily, the spider is sleeping. Flavia has only a few moves before the spider wakes up. The web is a circle ten centimeters in radius and Flavia can escape if she makes it to the edge of the web Each move is a random distance in the range of zero to five centimeters, in a random direction from zero to 360 degrees Write a program that determines if Flavia escapes. Ask the user for the number of moves Flavia can make before the spider wakes. Then loop until Flavia reaches the edge of the web or reaches the move limit. Here is one run C: \Csource\ Randomwalk> . exe Number of times the bug can move --10 Bug starts at (0.000, 0.00) Bug moves to (-2.61, -0.88), distance2.75 Bug moves to (-2.42, -1.55), distance2.87 Bug moves to (-2.22, 0.85), distance2.38 Bug moves to 1.22, 1.65), distance2.05 Bug moves to 3 Bug moves to 4.27,5.16), distance-6.70 Bug moves to 5.86, 1.24), distance-5.99 Bug moves to ( 5.67, 1.60), distance = 5.89 Bug moves to 5.50, 3.00), distance-6.27 Bug moves to 7.47, 1.96), distance7.72 YUM YUM. Spider eats the bug 3.40, 3.06),distance - Here is another: C: \Csource\ Randomwalk? . exe Number of times the bug can move -->15 Bug starts at (0.000, 0.00) Bug moves to (-2.26, -1.67), distance2.81 Bug moves to (-0.38, -1.91), distance1.95 Bug moves to 2.85, 1.88), distance3.41 Bug moves to 1.17,-1.33), distance1.77 Bug moves to (-1.08, 2.98),distance-3.17 Bug moves to (-3.67, 6.85), distance7.77 Bug moves to (-4.50, 7.57), distance = 8.81 Bug moves to (-5.41, 4.49), distance7.03 Bug moves to (-5.09,8.93), distance10.28 Oh No! The bug escapes Random Walk Flavia the fly has landed in the center of a spider web at X=0, Y=0. Luckily, the spider is sleeping. Flavia has only a few moves before the spider wakes up. The web is a circle ten centimeters in radius and Flavia can escape if she makes it to the edge of the web Each move is a random distance in the range of zero to five centimeters, in a random direction from zero to 360 degrees Write a program that determines if Flavia escapes. Ask the user for the number of moves Flavia can make before the spider wakes. Then loop until Flavia reaches the edge of the web or reaches the move limit. Here is one run C: \Csource\ Randomwalk> . exe Number of times the bug can move --10 Bug starts at (0.000, 0.00) Bug moves to (-2.61, -0.88), distance2.75 Bug moves to (-2.42, -1.55), distance2.87 Bug moves to (-2.22, 0.85), distance2.38 Bug moves to 1.22, 1.65), distance2.05 Bug moves to 3 Bug moves to 4.27,5.16), distance-6.70 Bug moves to 5.86, 1.24), distance-5.99 Bug moves to ( 5.67, 1.60), distance = 5.89 Bug moves to 5.50, 3.00), distance-6.27 Bug moves to 7.47, 1.96), distance7.72 YUM YUM. Spider eats the bug 3.40, 3.06),distance - Here is another: C: \Csource\ Randomwalk? . exe Number of times the bug can move -->15 Bug starts at (0.000, 0.00) Bug moves to (-2.26, -1.67), distance2.81 Bug moves to (-0.38, -1.91), distance1.95 Bug moves to 2.85, 1.88), distance3.41 Bug moves to 1.17,-1.33), distance1.77 Bug moves to (-1.08, 2.98),distance-3.17 Bug moves to (-3.67, 6.85), distance7.77 Bug moves to (-4.50, 7.57), distance = 8.81 Bug moves to (-5.41, 4.49), distance7.03 Bug moves to (-5.09,8.93), distance10.28 Oh No! The bug escapes

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

Step: 3

blur-text-image

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

Students also viewed these Databases questions