***********************************************************************
CS201 Lab 6, Winter 2008
Vectors
***********************************************************************
Change directory to cs201/lab6.
1. In this lab we develop a program to compute the mean (average) and
standard deviation of a set of numbers. The numbers can either be
entered from the keyboard (until ^D) or from a file (until end-of-file).
2. Let's label the numbers X1, X2, X3, ... Xn if n numbers were entered.
The mean and standard deviation (sd) are calculated as follows:
mean = (X1 + X2 + X3 + ... + Xn) / n
sd = sqrt( ((X1-mean)^2 + (X2-mean)^2 + ... + (Xn-mean)^2)) / (n-1) )
where sqrt stands for the square root function and X^2 means
X raised to the second power.
3. Problem analysis.
Since the sd formula uses the mean, we must compute the mean first
and at the same time store away the individual Xs (in a vector).
Once the mean is available, we can then recall each X to compute the
standard deviation.
Since we don't know how many numbers are there, we need to use a
vector and its push_back() member function to expand the vector as
needed.
You may use int, float, or double for the Xs, but you must use double
for mean and sd.
Since sd formula divides by (n-1), n must be greater than 1. Make sure
the program checks for that.
4. Standard deviation is a measure of spread of the data. For example, two
cities might have the same mean temperature but different standard deviations.
For example, Santa Monica might have the same mean temperature value of
50 degrees as Los Angeles, but the variation of the temperature in
Santa Monica over a year is smaller than Los Angeles because it is
closer to the ocean. Therefore the sd of temperature in Santa Monica
is smaller compared to Los Angeles.
For a normal distribution approximately 95% of the data points are within
2 standard deviations of the mean. For example, if there were 100 data
points in a normal distribution with mean 70 and sd 10, then 95 of the data
points fall in the range 50 to 90.
For 1, 2, 3, 4, 5, 6, 7, 8, and 9 which is not a normal distribution,
the mean is 5 and sd is approximately 2.7.
5. Hand in a printout of the program and a typescript of a sample run.