This lab will help you practice with vectors (and loops).
Statisticians have developed a wonderful way to visualize data which provides both the actual data and the shape of any curve which might be present -- all in one textual display. This display is called a stem-leaf plot. It is a two column listing of the data where the second column is all of the 1's digits and the first column groups by the 10's (and above) digits. For instance, you might have this plot from the data { 10, 7, 21, 43, 23, 9, 15, 34, 38, 25, 21 }:
5 | 4 | 3 3 | 48 2 | 1135 1 | 05 0 | 79
Note how you can see all the data points: 43, 34, 38, 21, 21, etc. Also the shape of a curve is apparent: there were many scores in the 20's and fewer in the 10's and 30's and so-on.
In order to do this you must have all of the data available and in order (i.e. sorted). (You might find the sorting lab a useful reference for this.) Once all the data are available and ordered, you can form the curve by removing the 1's digits from all of your data and organizing it in the second column of the 'plot' along side the 10's (and higher) digits which form the first column.
Let's work through it with the data set above for example:
(Hint: The backing up and processing forward bit is similar to how we reversed words in a string.)
Make sure the user is allowed to enter as much data as they want.
This assignment is (Level 3).
Add (Level 1.5) to print two stem-leaf plots: one of the original data and a second of the percentages of the data. In order to print percentages, you'll need to know the effective maximum of the data -- a new input. For instance, if the data set above were out of a maximum of 50, its percentage stem-leaf would look like this:
9 | 8 | 6 7 | 6 6 | 8 5 | 0 4 | 226 3 | 0 2 | 0 1 | 48 0 |
On the other hand, if the effective maximum were 40, the percentage plot would look like this (note the rounding):
11 | 10 | 8 9 | 5 8 | 5 7 | 6 | 3 5 | 338 4 | 3 | 8 2 | 35 1 | 8 0 |
It might be a good thing to pause the display of the data between the two plots. (Hint: maybe cin.get() could come in handy here?)
Add (Level 1) to give the user the option to round, truncate, or force up the percentages. (Perhaps you could call them the usual, pesimistic, and optimistic plots? *grin*) (For this to make sense you must either do the percentage plot option above -- so you can 'round' their percentages -- or read floating point data originally -- to 'round' the original data. Of course, you could do both...)
Add (Level 3) to skip longer empty ranges. For instance, if the data were { 10, 15, 64, 72, 68 }, you'd print:
8 | 7 | 2 6 | 48 5 | . . . 2 | 1 | 05
Instead of printing the entire thing. This should happen automatically whenever a blank range would be 4 or more long. (If it were 3 long, you'd just be replacing the middle line with the '. . .' thing.)
Add (Level 2) to do a second version of your stem-leaf algorithm which doesn't sort the data before printing the stem-leaf plot. (The plot should end up the same, but you don't really have to re-order the data before printing -- it just makes it easier.) You can place this version into a menu option or a second program: whichever you find easier. But you must script both versions for full credit.