This assignment is designed to give you practice using doubles
mathematical functions and writing programs with user-defined
Your assignment is to write a program
that computes the average and standard deviation for four values input
by the user.
To do this you will need to write three functions:
1. //explains program to user and directs them to enter
2. //returns the arithmetic mean of the four arguments.
double average(double s1, double
s2, double s3, double s4);
The average is the sum of the values
divided by the number of values (four in this case).
It is also called the arithmetic mean.
3. //returns the standard deviation of the four arguments.
double stdDev(double s1, double s2, double s3,
To compute the standard deviation:
- compute the average
of the n values
- for each value
compute the squared deviation (value - average)^2 (you are required to
use the power function
- sum the squared
deviations and divide by n-1 (three in our case) the degrees of freedom
- take the square root
(you are required to use the square
root function here)
Here is shell program
to get you
INPUT AND OUTPUT:
The program must prompt for four double values.
The program must compute the average and standard deviation of the
values and report them to the user.
After the results are reported the program must ask the user if they
would like to continue and either repeat or exit, depending on the
Have a look at the sample script
see how it should look when you run the program.
Your script should include at least 10 test cases, including the
- Examples in the sample script (link above)
- Positive numbers
- Negative numbers
- Real numbers
Here is the list of things you have to turn in:
- At the start of class on the due
date place the following item on the "counter" in
front of me:
- a hardcopy (printed listing) of your program (the C++ source
- Before midnight on the the due
date upload the following to the Homework Submission
- A copy of the source code (C++ code) (be sure your name is
in the comment section at the beginning of the program), named sprog3.cpp
- and a (filtered) script showing a test run of the program,
For the due dates, see the class schedule