Comp 1671, Autumn 2002
Programming Project 5
Assigned November 1, 2002
Due Friday, November 15, 2002

These are the instructions for your fifth programming project. As always, all code must be written individually and independently. Not a single line of code in your project should be written by another person. Recall that violating this rule will result in severe consequences.

This program will be your first that uses files and arrays. The program should begin by asking the user for the name of a data file. If the program cannot open the file, it should continue asking the user for the file name until a valid file is found and opened. This data file will contain a list of integers from 0 to 99. These numbers might represent, for example, scores on an exam or a person's height in inches. There will be an unknown number of data items in the file. The purpose of the program is to read in the data and print a summary of it. This summary should indicate the number of valid data items in the file (ignore numbers not in the required range and other invalid entries), the average of all of the valid numbers, and a histogram of the data. The histogram should have 10 bars and be laid out horizontally. If the data in the file is such that the histogram is wider than 80 characters, then make each mark in the histogram worth multiple elements of data. Round appropriately. The weight of each mark should be such that the histogram is as wide as possible, but fits within 80 characters. The display should indicate how many data units are represented by each mark. Each bar in the histogram should also be labelled with its corresponding range (0-9, 10-19, etc.)

In this project, you are not required to have specific functions with specific interfaces. Instead, you may design the function interfaces (that is, the names, parameters, and return values of the functions). However, you must use at least two functions other than main. For example, it might be useful to have a function that draws a histogram given an array of histogram data, or a function that calculates the maximum value of the elements in your histogram array.

Please note that this project does not require you to store the list of numbers in an array - each number can be processed as soon as it is read and so does not need to be stored. Instead, create an array with just 10 elements that you use to store the number of numbers that gets counted for each bar of the histogram.

Here is some sample program output:

ftl> proj5

This program reads a data file containing numbers between 0 and 99.  It outputs
the number of data items read, the average of the data, and a histogram for
this data.  The information will also be saved in a file called 'histogram'

What is the name of your data file? scores
Unable to open the file scores
Please enter the name of your data file: scores1.dat
There were 36 valid data items in your file.
The average value of these data items is 49.0833

Each X represents 1 data elements.

 0- 9: X
10-19: XX
20-29: XXX
30-39: XXXX
40-49: XXXXXX
50-59: XXXXXXXX
60-69: XXXXXX
70-79: XXX
80-89: XX
90-99: X

ftl> proj5

This program reads a data file containing numbers between 0 and 99.  It outputs
the number of data items read, the average of the data, and a histogram for
this data.  The information will also be saved in a file called 'histogram'

What is the name of your data file? scores3.dat
There were 1000 valid data items in your file.
The average value of these data items is 49.331

Each X represents 3 data elements.

 0- 9: XXXXXX
10-19: XXXXXXXXXXXXXXXXXXX
20-29: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
30-39: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
40-49: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
50-59: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
60-69: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
70-79: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
80-89: XXXXXXXXXXXXXXXXXX
90-99: XXXXXXXXX

ftl> proj5

This program reads a data file containing numbers between 0 and 99.  It outputs
the number of data items read, the average of the data, and a histogram for
this data.  The information will also be saved in a file called 'histogram'

What is the name of your data file? scores5.dat
There were 819 valid data items in your file.
The average value of these data items is 15.0183

Each X represents 12 data elements.

 0- 9: X
10-19: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
20-29: X
30-39:
40-49:
50-59:
60-69:
70-79:
80-89:
90-99:

ftl>

Here are the sample data files, including the ones that were used in the above program output:
scores1.dat
scores2.dat
scores3.dat
scores4.dat
scores5.dat

Instructions for submitting:
As always, don't forget that your program should start with a few lines of comments giving your name, the date, the course this is for, and the assignment number. You should also include a few lines that describes what the program does and how to use it. The program should be written with a well organized structure, and the variables should be named in a useful way. The program should be formatted consistently and clearly, and should include comments that explain the code. The program should compile without any compiler warnings. When you're done writing and testing the program, print out a copy of your source code. Also print out a copy of the output of your program, which shows how the program works for several different dates. Bring these to class on the due date and turn them in at the beginning of class. Also, before the beginning of class on the due date, mail your source code (your ".cpp" file) to comp1671@cs.du.edu. Do not include it as the message, instead make it an attachment to the email.

If you need further challenge: