Assignment 04

Due: Monday, Sept. 25, 2017 at noon 100 pts

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to submit a file for this course electronically, from the directory in which the file resides type in at the UNIX prompt the command: cssubmit 1570 section_letter assignment_number. Be sure that only the file you want to submit is in that directory - make a directory for every assignment! The submit system will deliver every .cpp file in the current directory to me. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.

Background: Poor Hans. For most of us, life is a trial - live one day at a time and we usually do pretty good with minimal effort. But for Hans Moleman, life is really tough. Being nearly blind, he has a hard time seeing, something most of us take for granted. But, he got new lenses for hi

d0 = initial number of feet from the house (20 for 1st walk, 21 for 2nd walk, etc),

di+1 = ( [( di * 214013 + 2531011) mod 2147483647] mod 200 ) + 100, i = 1, 2, 3, ...

If you are unfamiliar with an iterative formula like this, this is how it works. The first distance walked (as stated above) is 20 ft. You'll substitute this into the second equation above to compute the 2nd distance, d2. Then sub d2 into the equation to compute d3. Continue in this way. For his second walk, you'd start with first distance walked being 21.

The output from your program should be a listing of the instances when he either goes nowhere (ends up at home) or finds his way to Nick's office, and how many feet he traveled to get either of those two places. And, if the distance walked is greater than a mile, output that distance in miles. After that, output the percentages of times he got to Nick's, ended up at home, and got lost in the ozone. Part of my output looks like this:

Ended walk at total dist traveled (ft)

------------- ------------------------

.

s glasses and that should have solved his problems. But, alas, he got the lenses at the new super store in Springfield, Gal-Mart, which employs a Dr. Riviera who uses some ridiculous, crazy new formula for computing lens thickness. Now he can't hardly see what he's doing or where he's going with his glasses on. SO, he needs to get back to Dr. Nick's to have his sight re-evaluated and new lenses made. The office is 1414 feet from his house. He can't drive in this condition, and he's scared to death of buses, so he'll walk. The thing is, Hans may or may not make it to his intended destination! Three possibilities exist: 1) he gets to the doctor's office; 2) he ends up back home; and 3) after a long time, he's so far away that he is picked up by the local police and taken to a homeless shelter.

You're going to write a program that will simulate his walk across town. In fact, your program will generate 200 possible walks and gather statistics on the results.

Specifications: Your program will simulate 200 walks. A "walk" begins at home and proceeds from decision point to decision point until the walk terminates. Termination happens when a decision point is

  • with in 50 feet of Dr. Nick's office

  • with in 30 feet of home and there are at least 5 other decision points preceding this point

  • the 500th decision point

The first of the above conditions implies that he is close enough to his intended destination to be able to see that he has arrived. The second implies that he has been walking for a while and hasn't actually gone anywhere, so he just gives up and goes back inside and watches re-runs of the Simpsons! DOH! The third simulates a lost old man wandering off into the horizon never to return.

Details: At each decision point, he will almost always turn right. This is because his eye-sight is so screwed up that his vision "pulls" him in that direction. Also, he tends right because the bullies in town added 20 lbs of lead to his cane, which he carries in his right hand. However, every 7th decision point he turns left. (Why? I dunno, make something up.) Also, for the first walk, he will walk 20 feet away from his house to his first decision point. On the second walk, he walks 21 ft before the first decision point (note this is NOT the second step of the first walk). Etc...each first decision point is 1 foot further from the house than the previous one. You can choose the direction of this first move, but be consistent from walk to walk, starting in the same direction. And, the distance he walks after each decision point is given by

.

.

home 3144

home 34598 (~ 6.55265 miles)

home 21148 (~ 4.0053 miles)

home 10253 (~ 1.94186 miles)

Nick's 75673 (~ 14.332 miles)

home 48080 (~ 9.10606 miles)

home 39225 (~ 7.42898 miles)

home 6106 (~ 1.15644 miles)

home 1398

home 2597

home 19023 (~ 3.60284 miles)

. . .

Also: In order to code this problem, I'd suggest you establish a coordinate system for the location of Hans, the doctor's office and Hans's home. Since Hans starts his walks at home, put home at (0, 0). Since Nick's office is 1414 feet (straight line) away, put it at (1000, 1000). You can work out the rest from there. In order to compute the distance from one point to another, you will need to use the sqrt() function. It is contained in the library <cmath>. Just #include it like you do the iostream library. This function will return a float type and you will need to put what you wish to find the square root of inside the parentheses.

When you submit: Just submit, since there is no input from the user.

And, as always, let your instructor know if you need any help.