Lab 4
comp 125-609, Goldwasser
Tuesday, September 21, 1999

Purpose: Using files, loops and arrays.

Our goal is to take a file of test scores as input and to create a new output file which consists of those same scores sorted from highest to lowest. The technique we will use for doing this is known as a "counting sort" for reasons which will soon be clear.

The sort will proceed in two phases. During the first phase, pass through the input file while keeping a count of how many times each particular grade occurs. This can be done by keeping an auxiliary array count(0 to 100) As Integer as you proceed.

After reading all of the input, the second phase of the process begins, that of printing out the same list of scores but in decreasing order. Creating this output should be very straightforward by using the count(0 to 100) array.


Other issues:

Note that you will not be told the length of the input list ahead of time. You must keep reading the input until the end of file is reached. (You will want to use the EOF(n) function which will evaluate to true if the end of the file with reference number n has been reached.)

Your user interface can be quite simple. I would suggest one textbox w/ label to ask the user for the input file name, another textbox and label to ask the user for the output file name, and a command button labeled "Go" which will do the work. Please set up a default input file name and output file name at design time (to avoid having to always retype it when testing).


For testing your programs, here is a small and a large input file.
  • (1) Print out your project as follows. Click "File". Click "Print". In the Range box, select "Current project". In the Print What box, click on the "Code" box.
  • (2) Please call me over to your computer to run your program and to turn in your printout.