Programming Project # 2

Due: Thursday, July 2, 1998 before class


Project 2 will do an analysis of some undetermined number of positive integers. You will report the number of positive integers, the largest positive integer (the maximum value), the smallest positive integer (the minimum value), the sum of all of the numbers, and their average (to 2 decimal places).

To eliminate the need to test the user's input for validity, I will be providing a data file for you to use as input for your program. This data file contains positive integers. The last value in the file is -1. This is the sentinel value that signals the program to stop getting integers as input.

To use the data file as input for your program, you will use unix redirection. By using redirection, we can have unix fill the stdin buffer from a data file, instead of from the keyboard. The scanf statement that you use in your program will look exactly the same as it would if you were getting your input from the keyboard. Since you will be getting the values in from a file, instead of from a user typing at the keyboard, you don't need to (or want to) prompt the user.

When you run your program, at the unix prompt you will give the following command:

a.out < ~sbogar1/104/proj2.dat This is how unix redirection is done. It is saying to run your executable file, using the file proj2.dat as input. The file is in my gl account in a subdirectory called 104, so you will have to give the entire path as shown above.

Here is an example of what the data file might look like:

100 500 10 90 7 -1 Here is the sample output from a correct program using the example data file: There are 5 positive integers in the file. The maximum value is 500 The minimum value is 7 The sum of the numbers is 707 The average is 141.40 Notice that this program does NOT print out each of the numbers in the file. The data file could contain thousands of integers. We are only interested in the analysis of the integers we encountered, not seeing every one of them.


Make sure that you have used one of the indentation styles from the indentation styles handout consistently throughout your program, as well as following the coding standards described in the coding standards handout.
Last Modified: Thursday, 25-Jun-1998 15:32:43 EDT

Thursday, 25-Jun-1998 15:32:43 EDT