CSCI 240 - Assignment 5 - Spring 2007


Due: Friday, Feb 23, 3 pm
Points: 100

For this assignment, you will re-implement Assignment 3 (the temperatures program) using several functions that you will write.  You will be able to reuse much of the code from Assignment 3; some of it will move into the functions.  The one new feature that this version will have is the ability to restrict users from entering wildly unreasonable temperature values (see the getIntInRange() function.)

Your job is to write the following functions and modify your Assignment 3 program to use them.

double calcAverage(int sum, int count)

This function will calculate the average based on the sum and count arguments passed by the caller.  If count is 0, it should display an error message and return a value of -200.  The caller will then just display the -200 as if it were a valid average.  If count is not 0 the function will display nothing and return the average.

double calcSD(int sumXs, int sumXsquares, int count)

This function will calculate and return the standard deviation of a set of numbers, based on the arguments passed to it.  The arguments are:

int getIntInRange(int min, int max)

This function will accept user input and check to see that it is in the range specified by the arguments min and max.  If the value entered is not in this range, it will display an error message, including the desired boundaries:

Error: value entered is not in the range __ to __.  Try again:

(The __ should show the actual values of min and max.)

Then the program will accept a new value from the user and repeat the check.  This will continue until the user finally enters an in-range value.  The function will then return this value. 

Note that this function does not display anything except a possible error message.  The caller will have first displayed the regular prompt before calling this function.


Notes:

1. Suggestion: write and test the functions one at a time.  calcAverage() is the simplest, so do it first; then calcSD() and then getIntInRange().

2. For this program, when calling getIntInRange(), supply values of -150 and +150 as the arguments:

someIntVar = getIntInRange(-150, 150);  // do not use the name "someIntVar" !!

3. Note that calcAverage() and calcSD() will each be called twice in this program - once for the lows and once for the highs.  Therefore, different variables will be passed for each call (although the count arguments will be the same).

4. Important: read the Coding and Documentation Standards and use them in this program, including the standards for functions.  You will lose credit (up to 20%) for not following these standards carefully.  Check with you instructor or TA if you have any doubts.