University of California, Santa Cruz

Prof. Paulo Franca - Spring 2000



Guidelines for labs

Lab sections

Take quiz & check grades

Programming assignment #1

Due date: Sunday, October 10th, by midnight.

Brief description:

In this assignment you are to write a program that reads records from a disk file, insert the records in a Heap ADT and, after all the records are inserted, remove each one of them from the Heap and print as you remove.

Hint #1: I suggest you first implement a "fake" heap ADT where the records are sequentially inserted / removed in an array. After this is working and you have a good understanding of the heap structure, modify the ADT to work with a real heap.

Detailed description:

Records in the disk file consist of a name (char [20]) and a rank (float). All records are fixed lenght and unformatted. If you are not used to reading unformatted files in binary form, check the instructions. You do not know in advance how many records are there. For array dimensioning purposes, you may assume that no more than 50 records will be present.

Both your main program and your ADT should be, as much as possible, independent from the record format (at least at the source code level).

By independence from the record format, I mean that, if you have to use a different structure for your records, the actual source code of your main program and your ADT do not have to change. It is OK that you may have to recompile.

For those of you who are not familiar with this requirement, what you need to do is to include a set of functions to manipulate the record structures in a similar way that you do with an ADT, with the exception that you will not be required to write those functions in a separate file. You may include them with your main program file if you wish. Typical functions for this purpose are:

bulletread a record from the disk
bulletread a record from the keyboard
bulletdetermine if all records were read (end of file)
bulletdisplay contents of a record to the screen
bulletcompare two records to determine if the first is less than, equal to or more than the second (based on the value of rank).

The sample program "testfile.c" illustrates how you can generate a test file. This program also illustrates how you can make your main program independent of the record structure. Notice that only the main program is provided in this example.