Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

lost dogs visual basic program. I have the code for 1 dog but i need the second part of the code which is for 1000

lost dogs visual basic program. I have the code for 1 dog but i need the second part of the code which is for 1000 dogs i need this code exactly what the discription says please and thank you!

Lost Dogs

A dog is lost in a tunnel. It can move one node at a time in either direction, left or right. (2 random numbers can determine the direction).

Nodes 1 ------- 2 ------- 3 ------- 4 ------- 5 ------- 6 ------- 7 ------- 8 ------- 9

The dog starts at node 5 (dogs value is 5) and escapes the tunnel at node 1 or node 9. If the dog hits node 2 a force of nature propels it to node 7. How long does the dog stay in the tunnel if it takes 1 minute to move between nodes? Count the total moves (minutes) of all the dogs by restarting a dog at node 5 one thousand times. Calculate the average time it takes the 1000 dogs to exit the tunnel.

You may now see the reason for keeping things as simple as possible. Should I write the program for all 1000 dogs right at the start. Probably not. What can I do to simplify it? Write the Do-While part for ONE dog first and be certain it is moving properly and escapes. Then I can consider what to do with the 1000 dogs. Break each part into simpler steps.

The form should have a Start Dog button and a Label to display the average number of minutes the 1000 dogs took to escape.

You do NOT need any graphics to show the dog moving. This is only a simulation.

Hint: I could use a random number that is either a 0 or 1. A random number 0 could be right and 1 left. See the Coin Toss (Chapter 5) example in the book.

So, if the random number is a 1 what would happen to the dog? Answer: subtract 1 from dog, his value would then be a 4, indicating he had moved left to node 4. Then a new random number would be generated inside the loop to make the next move.

Hint 2: You may need a For-Next loop for the 1000 dogs. Inside that For loop you may need a Do-While loop to move each dog until it escapes.

If you have errors or questions feel free to send me a message. But you may need to attach your zipped program in the message. I will give a clue or indicate where to look for the error or problem.

A, Logic Escape Plan For One Dog

Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' Logic Plan for One Dog Escape Randomize() Dim escape_minutes = 0 Dim randomPos As Integer Dim dogPos As Integer = 5 'While dogPos <> 1 Or dogPos <> 9 While True escape_minutes = escape_minutes + 1 ' Generates random number either 0 0r 1 randomPos = CInt(Int((2 * Rnd()) + 0)) If randomPos = 1 Then dogPos = dogPos - randomPos ElseIf randomPos = 0 Then dogPos = dogPos + 1 End If If dogPos = 1 Then Exit While End If If dogPos = 9 Then Exit While End If End While Label1.Text = escape_minutes & " minutes" End Sub End Class

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions