![]() |
Computer Science Department |
Objectives: |
Practice using an array to solve a real problem. |
Background: |
Standard deviation is a measure of the spread of values
around a mean. The higher the standard deviation, the more the values
are scattered away from the mean. To calculate, one must first
calculate the mean (average) and then use that mean to calculate the
distance of each value from the mean. These distances are squared to
account for numbers both less than and greater than the mean value.
From Wikipedia: In other words, the standard deviation of a discrete uniform random variable X can be calculated as follows: 1. For each value xi calculate the difference xi - x between xi and the average value x. 2. Calculate the squares of these differences. Sum the squares of the distances. 3. Find the average of the squared differences. This quantity is the variance σ2. 4. Take the square root of the variance. |
New Terms: |
Command line argument
Mean Standard deviation |
Materials: |
You will write this program from scratch.
You may use the following file for testing: testData. To use the file, run your program in the command line environment and override standard input. See demo at the beginning of class for this technique. Submit is available for this lab. |
Acknowledgment | Adapted from a lab by Nancy Harris |
Add to your Helper file a function, stdDev, that computes the standard deviation of a passed array of double numbers. See the formula above. Your standardDeviation function should use the mean function created in Part 2 above.Again, you should insure that the array is not null and that it has more than 0 elements. If either of those two conditions is true, return 0.
Updated 11/09/11 (nlh)