Programming Project # 2
Out: Tuesday June 29, 1999
Due: Tuesday July 6, 1999 before 6:00 PM
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
a.out < 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,
proj2.dat, can be seen by following this link. Within your gl account,
bring up Netscape, go to this link and then under the File menu chose the
Save As option. This will save a copy of the proj2.dat file into your
directory so that you can use it as input. This is most easily accomplished
if you use the SGI machines in ECS 005, rather than either the IBMs or Macs.
DO NOT just cut and paste to capture the text and put it into a file, because
you may capture some unwanted extra spaces.
Here is an example of what the data file might look like:
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.
Tuesday, 29-Jun-1999 16:21:46 EDT