jamesben91
May 22, 2014, 07:50 PM
A common programming task is computing statistics of a set of numbers. (A statistic is a number that summarizes some property of a set of data.) Common statistics include the mean (also known as the average) and the standard deviation (which tells how spread out the data are from the mean). If calc is a variable of type StatCalc, then the following methods are
defined:
• calc.enter(item); where item is a number, adds the item to the dataset.
• calc.getCount() is a function that returns the number of items that have been added to the dataset.
• calc.getSum() is a function that returns the sum of all the items that have been added to the dataset.
• calc.getMean() is a function that returns the average of all the items.
• calc.getStandardDeviation() is a function that returns the standard deviation of the items.
Typically, all the data are added one after the other by calling the enter() method over and over, as the data become available. After all the data have been entered, any of the other methods can be called to get statistical information about the data. The methods getMean() and getStandardDeviation() should only be called if the number of items is greater than zero.
The getMax() method should return the largest of all the items that have been added to the dataset, and getMin() should return the smallest.
Test your new class by using it in a program to compute statistics for a set of non-zero numbers entered by the user.
Read numbers from the user and add them to the dataset. Use 0 as a sentinel value (that is, stop reading numbers when the user enters 0). After all the user’s non-zero
defined:
• calc.enter(item); where item is a number, adds the item to the dataset.
• calc.getCount() is a function that returns the number of items that have been added to the dataset.
• calc.getSum() is a function that returns the sum of all the items that have been added to the dataset.
• calc.getMean() is a function that returns the average of all the items.
• calc.getStandardDeviation() is a function that returns the standard deviation of the items.
Typically, all the data are added one after the other by calling the enter() method over and over, as the data become available. After all the data have been entered, any of the other methods can be called to get statistical information about the data. The methods getMean() and getStandardDeviation() should only be called if the number of items is greater than zero.
The getMax() method should return the largest of all the items that have been added to the dataset, and getMin() should return the smallest.
Test your new class by using it in a program to compute statistics for a set of non-zero numbers entered by the user.
Read numbers from the user and add them to the dataset. Use 0 as a sentinel value (that is, stop reading numbers when the user enters 0). After all the user’s non-zero