UMBC CMSC 104 * CSEE | 104 | current 104

Programming Project # 2 Fall 1998 -- Sections 103 and 301

This project is due at midnight on the due date.
Section 103 -- Wednesday November 11, 1998
Section 301 -- Tuesday, November 10, 1998

Help is available for this project from the Help Center in room ECS332, and from the TA (jfan1@gl.umbc.edu)

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.

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

a.out < /afs/umbc.edu/users/d/e/dennis/pub/cs104/proj2/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 so you will have to give the entire path as shown above. You may find it easier to copy to your own directory temporarily.

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.

5-Point Bonus Opporunity
Enhance your program to handle the possibilty that there are NO positive integers in the file -- i.e. the file contains only a -1. In this case, your output should indicate that the largest value is 0, the smallest value is 0, the sum is 0, the average is 0.0 and there were 0 integers entered. Test your program using the file /afs/umbc.edu/users/d/e/dennis/proj2/proj2B1.dat

Another 5-Point Bonus Opportunity
Enhance your program to accept input from the user (with an appropriate prompt) as well as from the file. Also enhance your project to ignore 0 and negative numbers other than -1 that are input by the user or appear in the file. Your program should provide a simple (but polite) error message to the user which includes the invalid integer. Test your program using the file /afs/umbc.edu/users/d/e/dennis/pub/cs104/proj2/proj2B2.dat


Submitting your progam

Once your program compiles and is tested, enter the following Unix commands


       $ script
       $ cc proj2.c
       $ a.out < /afs/umbc.edu/users/d/e/dennis/pub/cs104/proj2/proj2.dat
       $ exit
       $ mv typescript proj2.out

Now submit your source file (proj2.c) and your output file (proj2.out) using the submit command as discussed in class.


Make sure that your file header comment contains all necessary information including your algorithm. Also 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 and as discussed in class.



Thursday, 29-Oct-1998 15:25:22 EST