Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program The local town drunk, Harvey, has gotten himself into a mess. Besides being in his normal state, a state that earned him his

C++ Program

The local town drunk, Harvey, has gotten himself into a mess. Besides being in his normal state, a state that earned him his title, he has made his way into the Flowers Unlimited Park, a park where many flowers are grown and display in their natural beauty. The local ordinance fines individuals $3.00 for each flower they pick or destroy. This is enforced to insure the beauty and the integrity of the park. Now old Harvey is not only in the wrong state, drunk, and in the wrong place, the park, he is also on a small island within the park, twelve feet wide by 14 feet long. The island is connected to the main land by two bridges one at each end of the island. Now Harvey needs to get across the island and in the process, it will cost him (ie stepping on flowers to get off the island).

There is a clear path down the middle of the island that leads from one bridge to the other. The remainder of the island has flowers. On the island, there are two flowers growing per square foot. What we need to find out is how much is it going to cost Old Harvey to walk from where he is, the end of the bridge, onto the island (ie first step forward puts Harvey on the island) to end at either bridge and get off the island. The simulation starts when Harvey steps off the bridge and onto the island.

After studying Harvey for many years, it is known that he doesn't walk a straight line when he is in his preferred state. His walking patterns are as follows. He steps forward 48% of the time, he steps right 25% of the time, left 20% and backwards 7% of the time. If Harvey steps on the other end of the bridge, we will consider that he has made it across the island. If he steps into the water, he has finished walking and must be rescued. If he steps off the path onto a square containing two flowers, he destroys one. If he steps into the same square later, he destroys the second flower. If he steps into the same square any other times, there are no flowers, it cost nothing.

Write a program that will compute the cost of Harvey's walk in the park.

Inputs: None

Outputs: The cost (average) of Harvey's walk. The number of times Harvey made it across bridge.

The number of times Harvey had to be rescued from the water.

Restrictions: Use a 2-d array. Run the simulation 3500 times to generate the results.

Output: Format output in a readable style.

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

More Books

Students also viewed these Databases questions