COSC 110

Exercise #5

 Write a complete C++ program on paper to process numeric data contained in a file.  Assume that you have a file named beginner.txt which contains many, many integer values between -1000 and +1000, each separated from the next by spaces or a newline character.  You are not allowed to use the computer at all in writing this program.

 1. Read the integers from the file one at a time.  For each number you read, count it in one of three categories:  positive, negative, or zero depending on the value of the number.

 2. Also for each number that is positive or negative, add the value to a sum.  Add positive numbers to the positive sum and negative numbers to the negative sum.

 3. Continue reading until all numbers in the file have been processed.

 4. When reading is finished, display (with identification) the counts for the positives, negatives, and zeros readAlso, display the sum of the positives and the sum of the negatives, with identification.

 Below is a miniature sample of what numbers.txt might look like:

34  0  89  332  -90  567  21  101  -23  0  -890  -1  0 208  567  220
-3  65  903  -39  -606  0  28  -90  120
15
11  655  -1  0  20  390  -401  7  11  188  -78  9  -505

For this file, your program should get these results.  The exact form of the display is up to you.

The beginner.txt file contains:
22 positives with sum 4561
12 negatives with sum -2727
5 zeros

You may work with one or two other students on this exercise.  I recommend that you write in English (or pseudocode or flowcharts or in a sketch) what needs to be done for each step.  Then, put your ideas together into a C++ program through discussions with your partner(s).  Hand in your team's program on a sheet of paper - make sure to include all team member names and to write clearly.  You may use minimal comments in your program - a brief statement of purpose, the names of the partners and the section is sufficient.  Otherwise, the program should be complete.

Possible Extra Credit:  If you get this program written and want to try for more points, answer this queston.  Suppose that there is a second file named alternate.txt with the same structure as beginner.txt, containing all integer numbers (but different ones), how can the program be changed to process both files and report the number of positives, their sum, number of negatives, their sum and number of zeros for each file.  Do NOT change the program to do this; just provide a discussion describing the change - be as specific as possible.