The George Washington University
School of Engineering and Applied Science
Department of Computer Science

CSci 131 -- Algorithms and Data Structures I
Project #4

Due Date: November 7, 2000

The purpose of this project  is to give you more practice in dealing with generic packages, and illustrate the advantages of a clearly-specified generic interface in supporting multiple implementations and multiple clients.

In Project 3 you developed a generic table handler package that uses ordered arrays for the tables. In this project you have two main subtasks: modify the package to support "active iteration," and modify your CD user interface to do a calculation that takes advantage of the iteration.

A. Modify your Tables_Generic package to support active iteration. This concept is explained on p. 358-359. You do NOT need to read the rest of Chapter 9 to understand this short section.

  • Add an exception TableLocked to the upper part of the package spec.
  • Add two fields--Iterating (a Boolean) and WhichElement (an array subscript)--to the TableType declaration.
  • Modify the other table operations, to check the value of the Iterating flag and raise TableLocked if the operation is called while an iteration is in progress. Each of the operations will have this code right after the BEGIN:

  • IF Table.Data.Iterating THEN
      RAISE TableLocked;
    END IF;
  • Add these short operations to the table package

  • PROCEDURE StartTraversal (Table: IN OUT TableType);
    FUNCTION RetrieveCurrentElement (Table: TableType) RETURN Element;
    FUNCTION MoreElements (Table: TableType) RETURN Boolean;
    PROCEDURE MoveToNextElement (Table: IN OUT TableType);
    PROCEDURE StopTraversal (Table: IN OUT TableType);


B. Now add a menu selection to the CD user interface, "summarize". When the user selects this option, an active iteration will go through the table and collect the following information as each record is processed:
  • Number of CDs in each category (you can just use four Natural variables for this)
  • Total value of CD collection (a Currency value)
After the iteration, display the results on the screen.