CSCI 240 -- Assignment 3 -- Spring 2007

CSCI 240 -- Assignment 3 -- Spring 2007


Points: 100
Due: Monday, 2/12/07 - 3 pm

For this assignment, you are to write a program that accepts pairs of numbers from the user. Each pair represents a high and a low temperature reading for a day. The user can enter as many pairs as desired - after each pair, the program will ask if there is another pair or not. When the user finally indicates there is no more data to enter, the program will calculate and display (with appropriate labels) the following information:

The program should display some introductory explanatory information. A sample run of the program should resemble the following. (The 99.99s represent the user input and results.  They are not actual or correct values.)

Temperature Statistics Program

This program will prompt you to enter a series of daily high
and low temperatures. After you have entered each pair, you
will be asked if there is another pair... etc.

Continue? (y/n) y

Enter a low temperature: 99
Enter a high temperature: 99
Another? (y/n) y
Enter a low temperature: 99
Enter a high temperature: 99
Another? (y/n) y
Enter a low temperature: 99
Enter a high temperature: 99
Another? (y/n) n

Temperature Statistics

Lowest low temperature: 99
Lowest high temperature: 99
Highest low temperature: 99
Highest high temperature: 99
Average low temperature: 99.99
Average high temperature: 99.99
Standard deviation of low temps: 99.99
Standard deviation of high temps: 99.99

Notes

1. Input data as integers.

2. The "Continue" prompt gives the user a chance to quit before entering any numbers. If the user enters anything other than "y" or "Y" then exit the program immediately.  Use a decision with a compound condition (In English: "if the response is not "Y" and it is also not "y"). Then if this is true (so the program should exit), code:

exit(0);

to accomplish this.

If your program does not exit (i.e. the user entered "y" or a "Y"),  the next section of your program will be a loop that collects data from the user until a character other than a "y" or "Y" is entered.  The exit condition from this loop will be similar (but probably not identical) to the condition shown above.  Here's pseudocode:

do
  {
  get a high temp
  process it (accumulate, test, etc.)
  get a low temp
  process it (accumulate, test, etc.)
  ask "another?" and get response
  }
while (response is "y" or "Y");

4. You will want to keep track after each new temperature of the lowest low and high temperatures so far and the highest high and low temperatures so far. Define four variables to track these, and initialize the 2 "highests" to -200 and the 2 "lowests" to 200. Then change them anytime you get a low temperature lower than the current low value (and similarly for highs). This assumes that no temperature will be entered outside the range of -200 to 200.  You do not have to check for this.

5. Be very careful about any divisions of ints. Make sure you type cast one of the operands to double to retain decimal places.

6. The formula for standard deviations depends on the sum of the numbers, and the sum of the squares of the numbers. So you will need to accumulate these quantities (separately for highs and lows) as you process each input number.  This formula will be covered in class briefly.

SD  =  sd.gif (1333 bytes)

7. Check the results of your work with simple sample data. To help you, the standard deviation of the numbers 2, 3, 3, 3, 4 is about .707

Hand in the usual, paying close attention to variable names and formatting (including blank lines and other "white space" to make the code readable.  Beginning next assignment, we will use the course Documentation Standards which you might want to look at and begin using now.