Assignment 05

Due: Tuesday, March 16, 2021, at noon, 100 points

For this assignment, you will submit multiple C++ compilable files containing a program written in C++. Of course, you will submit in the usual (correct) way.

Background: After having an existential crisis, Bart is back! And boy is he more than ever ready to get started making more money. Bart comes back to his casino to find it in ruins! He knew it was a bad idea to leave the keys to Ralph (Ralph ended up gluing all the poker chips together but that’s a story for another day).

To bring back business, Bart plans to target a new clientele: mid-life crisis adults. There are upsides and downsides to mid-life crisis adults. The upside is that they spent copious amounts of money at a casino. The downside is that they have a conscience that tells them to go back home to their families. So, what Bart wants to do is come up with a simulation so he can figure out approximately how many crisis adults will be coming to the casino each day. And knowing you from previous projects, he has decided to hire you yet again.

Bart has found that, whenever a person leaves their home, on the first block there is a 100% chance that they will walk towards the casino. After walking another block, there is a 95% chance that they will continue walking towards the casino. In the next block, the person has a 5% chance that they will walk back towards home, due to their guilt. After another block, there is a 90% chance they will continue walking to the casino and a 10% chance they will walk towards home.

As you can see, each block they walk will reduce the chance of reaching the casino by 5%. You are to simulate 10,000 trips from the bar for a given distance between the casino and the person’s home. Some of those trips will end up with the mid-life crisis adult at home, some cases the adult will arrive at the casino. Bart wants to know what percent of the time do the adults end up at his casino.

Example: Consider the following example in which the adult has to walk 4 blocks from their home to the casino. Their home is at block 0. The casino is at block 5. The adult always starts at block 1.

Block 0

Block 1

Block 2

Block 3

Block 4

Block 5

Casino

In the first step, there is a 100% chance that the adult will walk towards casino. The adult moves from block 1 to block 2.

Block 0

(Home)

Block 1

Block 2

Block 3

Block 4

Block 5

Casino

Now, there is a 95% chance that the adult will continue towards the casino. Assume that they do, moving from block 2 to block 3.

Block 0

(Home)

Block 1

Block 2

Block 3

Block 4

Block 5

Casino

Now, there is a 90% chance that the adult will continue towards the casino. Assume that they actually head back to the home (which has a 10% chance). Now, the adult is back at block 2.

Block 0

(Home)

Block 1

Block 2

Block 3

Block 4

Block 5

Casino

The chance that the adult will head to the casino is now 85%. Assume the adult heads towards the casino... back to block 3.

Block 0

(Home)

Block 1

Block 2

Block 3

Block 4

Block 5

Casino

There is now an 80% chance that the adult will walk toward the casino. Assume that the adult continues towards the casino, making it to block 4.

Block 0

(Home)

Block 1

Block 2

Block 3

Block 4

Block 5

Casino

There is now a 75% chance that the adult will walk that last block towards the casino. However, there is a 25% chance that the adult will head back towards home. If so, the chance that they get to the casino will diminish quickly.

Specifications: Code this in C++. Submit it.

Note: As with the last assignment, you need to write your program using more than just an "int main()" function. This project requires many functions and it will be your duty to determine the functions to build this project. Your decision(s) will determine readability, expandability, modifiability, reuseability of the code. In other words, make it a good design. Don't cram all the functionality into main or any other particular function. It is also important that you make any function do one dedicated task, not a whole bunch of stuff.

Your program is to read in from the user two pieces of information: a maximum distance and a minimum distance from the casino to home. Then it is to run a simulation of the “Mid-Life Crisis Walk” 10,000 times for each of the distances read in. Therefore, if min=5 and max = 10, then there will be 10,000 runs of the walk for 5 blocks, 10,000 runs for the walk for 6 blocks, …, 10,000 runs of the walk for 10 blocks. In each case, you will tally the number of times they end up at the casino and divide by the number of attempts (10,000) to report a probability (expressed as a value between 0 and 1 OR as a percentage) that they get to the casino. Your output should state the parameters of the experiment (the number of trial walks), and the probability each person arrives at the casino, for each of the integer values from min to max. Make this presentation of results clear.

As usual, if you have any questions, be sure to ask your instructor.