Mixing Arrays and Classes: An array of simple types within a class

advertisement
Performing Calculations Using an Array
The objective for this exercise is to provide you with an opportunity to pull
together the two major concepts that we've worked with recently: using arrays,
and using basic classes. For this exercise, you will be provided with a starter
class (a 'skeleton', if you will), and you should fill in those methods that are
marked with 'TODO'. Included below is an example transcript of what your
program should look like when it's run, after you've successfully implemented all
the methods.
Example Transcript:
Data set 1 (Version 1): Avg: 6.00
**
****
******
********
**********
Data set 1 (Version 2): Avg: 7.20
*****
*******
******
********
**********
Data set 1 (Version 3): Avg: 7.20
*******
*****
******
********
**********
Data set 1 (Version 4): Avg: 7.60
*********
*****
******
********
**********
Data set 1 (Version 4): Avg: 7.60
Data set 2 (Version 1): Avg: 8.00
Data set 1:
*********
*****
******
********
**********
Data set 2:
**********
*********
********
*******
******
Press any key to continue . . .
What you need to do for this exercise:
1. Implement the GetAverage and PrintBarChart methods in the BarChart
class.
a. GetAverage should return the average of all five values in the object’s
array (no matter what values are stored in the array).
b. PrintBarChart should produce output that matches the above example
output. So if slot zero in the array contained the value 2, and the
following array elements contained 4, then 6, then 8, then 10, the
correct output of this method would be:
**
****
******
********
**********
2. You may want to run the sample code that has been provided to you, and
confirm that it produces the above, example output. You can do this by this
running the code in the RunExercise method of the BarChart_Demonstration
class.
Download