Due: Friday, April 3, 2020, at noon, 100 points
For this assignment, you will submit multiple files containing a program written in C++. Name your files meaningful names and give them proper extensions.
Background: Groundskeeper Willie, the mental giant that he is, spends a lot of time wandering about Springfield drinking his latest acquisition of Scotch. During his ramblings, which tend to be quite random in nature, his eyebrows tend to sag and he often loses his wallet, and sometimes even his pants. This he really doesn't care about, but he also tends to lose his dignity: he eventually runs into something and knocks himself out - whereupon people usually laugh at him, fall over him, or steal his wallet. He wants you to write a program that will help him determine where he might have lost his dignity. So, your program is to generate "random walks"; he figures they can save him a lot of time by having your program generate the random walk for him! Then he won't have to waste precious "drinking time" on his feet getting exercise.
Specifications: Your program is to produce what is known as "random walks". To clarify, imagine you start at a base point (if you are mathematically inclined, you could call it the origin) and move some random distance in some random direction (in a straight line) to a new point (x1, y1). When you get to this point, you again move some random distance in some random direction to another new point, say (x2, y2). Repeating this procedure N times creates a "random walk". You end up at the point (xN, yN). If you were Groundskeeper Willie, at this point you might fall down, possibly lose your wallet, watch, dignity, and some saliva. Thus, it is a good idea to remember where you landed.
You are to generate M of these walks, keeping track of the final points in an array for later reference. Willie figures he might have to return to that point in Springfield where he fell in order to look for his wallet, watch, dignity, rake, etc. After generating this set of random walks, you will report (output) the average distance from the starting point to the ending points of the walks. To do this, of course, you will calculate the distances and average them. You will also report the shortest, longest, and median walk distance. (The median of a set of data is the point
above which half the data lie and below which half the data lie. If the size of the data set is odd, then the median is a data point. If the size of the data set is even, then the median is the average of the middle two data points.) In order for you to find the median, you will have to sort the array of points (increasing order) by distance. You could accomplish this by creating another array of distances and sort that array.
It needn't be said at this point, but I will: you will use functions in this assignment fully. You now decide how to break up the program into functions. You also already know how to use multiple files for a program.
Special Stuff: So, you will use the rand() function to generate two things for each segment of a walk: the length of the walk (before another turn) and the angle to describe the direction of the walk. For this assignment, use the positive angle counterclockwise from the positive x-axis to determine the direction of the walk segment. So, generate a random number between 0 and 359 to represent the degree angle. Then, you will have to convert that to radians. Why? Because in order to determine the ending point, you will use the sin and cos functions from <cmath> (also to be included). These functions take radian arguments and return doubles . You can figure out the mathematics (trigonometry).
When you submit: You can play around with the parameters of this assignment when you are on your own, but when you submit, we want you to use the following parameters:
generate 100 walks
each walk has 50 segments
the maximum segment length (distance in any direction before changing directions) is to be 20 (the units here really don't matter....in Willie's case, probably feet)
You will notice that there needn't be any user input for this program!
As always, don't hesitate to ask questions if you have them.