THIS IS AN OPTIONAL ASSIGNMENT. You can do it if you are unhappy with your grade on Assignment 5. Your grade on this assignment, if you choose to do it, will replace your grade on Assignment 5. Note that by turning in this assignment, you are affirming that (1) You have not discussed the assignment with anyone except Professor Eck; (2) You have not looked anyone else's work; (3) You have not shown your own work to anyone.
The assignment must be turned in by Friday, March 21.
The assignment is basically taken from project 8 on page 220 of the text, with some added details about the requirement. Your program will make bar charts with vertical bars. The chart will be made up of characters and printed to the console, and the user will also have the option of saving the chart to a file. Here is an example of what the chart might look like:
+--------------------------X---------------------+ 25.2 | X | | X | | X X | | X X | |----------X---X-----------X---------------------| 18.9 | X X X X | | X X X X | | X X X X | | X X X X X | |------X---X---X-----------X-----------X-------X-| 12.6 | X X X X X X X | | X X X X X X X | | X X X X X X X X | | X X X X X X X X X X | |--X---X---X---X---X-------X-------X---X---X---X-| 6.3 | X X X X X X X X X X X | | X X X X X X X X X X X X | | X X X X X X X X X X X X | | X X X X X X X X X X X X | +--X---X---X---X---X---X---X---X---X---X---X---X-+ 0 1 2 3 4 5 6 7 8 9 10 11 12
The best way to make such a chart is to build it in a two-dimensional array of chars, and then to output the array. The array should not include the numbers at top and right -- the numbers can be added during output.
The chart will be defined by data values that are entered by the user. The program should be able to handle up to 15 data values. The values can be non-negative real numbers (of type double). The program should begin by asking the user how many data values there are. It should read the response. Then it should prompt the user for each data value, and store the values in an array. The data values will determine the height of each bar in the chart.
The chart itself can be stored in a 21-by-62 two-dimensional array of chars. The number of columns that are actually used in the array will be determined by the actual number of data values, but you don't have to use a dynamic array -- just fill as much of the array as you need. Fill in the array to represent the border and horizontal lines in the chart, then add the vertical bars to represent the data. The vertical scale on the chart should be adjusted so that the bottom row of the chart represents 0 and the top represents the maximum data value. The other three horizontal lines in the chart then represent 3/4, 1/2, and 1/4 of the maximum data value. If max is the maximum data value and val is any one of the data values, then the number of X's that you need for that value is
(int)( val/max * 20 ) + 1
After you have collected the data and created the chart in an array, you should print the chart to cout. Try to make it look as much like the example given above as possible. After printing the chart, ask the user whether the user would like to save the chart in a file. If the user answers yes, ask the user for the name of the file and then save a copy of the chart into the file. The chart in the file should look the same as the chart on the screen.