OBJECTIVE:
This assignment is designed to give you practice using
doubles
in
mathematical functions and writing programs with user-defined
functions.
THE ASSIGNMENT:
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
appropriate values.
void printDirections();
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,
double s4);
To compute the standard deviation:
- compute the average
of the n (4 in our case) values
- for each value
compute the squared deviation (value - average)^2 (you are required to
use the power function
here)
- 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
started.
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
user's choice.
Have a look at the
sample script to
see how it should look when you run the program.
TESTING:
Your script should include at least 10 test cases, including the
following:
- Examples in the sample script (link above)
- Positive numbers
- Negative numbers
- Zero
- Integers
- Real numbers
WHAT TO
TURN IN:
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
code).
- Before midnight on the the due
date upload the following to the Homework Submission
System:
- 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,
named sprog3.script
DUE DATES:
For the due dates, see
the class schedule.