The George Washington University
School of Engineering and Applied Science
Department of Computer Science
CSci 131 -- Algorithms and Data Structures I
Lab #5
For labs meeting the week of Sept. 26, 2000

This lab involves working with generics.

Develop a generic procedure that can be instantiated for an enumeration type. This procedure will simply display the values of the enumeration type, in the order in which they are defined, in a tabular form. The spec for this procedure will be

GENERIC
  TYPE Enum IS <>;
PROCEDURE DisplayTable;
Each cell in the table should be the same width (number of characters). The width of a row should not exceed 60 characters.

The number of rows and columns in the table will depend on the number of literals in the enumeration type, and on the number of characters in the widest literal. Luckily, Ada has some useful attribute functions to help with this. The number of literals in a type E is, of course, E'Pos(E'Last) + 1; the width of the widest literal is given by E'Width.

To display a row, write the proper number of literals into a string, then display the string. Ada.Text_IO.Enumeration_IO provides a procedure to help here:

PROCEDURE Put(To: OUT String;
              Item: IN Enum;
              Set: IN Type_Set := Default_Setting);
This procedure outputs the value of the parameter Item to the given string, using the length of the given string as the desired width; the string is right-padded with blanks. The string can be given as a slice, so you can control exactly which positions in the string will be occupied by each value.