' Assignment 3 for CSCI 431

Assignment 3 for CSCI 431

Overview

In this assignment you will experiment with the facilities in Ada for implementing Abstract Data Types. You will use an Ada package which provides the data type SET_OF_CHAR (set of characters). The package encapsulates both the type declarations for the SET_OF_CHAR variables and the procedures/functions which provide set operations such as UNION and INTERSECTION. You will explore how the implementation details can be hidden from programs using the data type. In this assignment, you will use three files of Ada code: charset.ads, charset.adb, chardriv.adb. The files charset.ads and charset.adb contain the specification and body of an Ada package called CHARSET which provides the SET_OF_CHAR data type. Another file, chardriv.adb, contains a simple program called CHARDRIV which uses the SET_OF_CHAR data type. This driver program simply reads two lines of text and forms sets containing the characters from each line. The sets are then printed along with union and intersection. Study the CHARSET package and examine how the data type SET_OF_CHAR is implemented. A SET_OF_CHAR variable is an array of booleans, indexed by the characters; the type declaration is:


     type SET_OF_CHAR is array (CHARACTER) of BOOLEAN;

A character is in the set if the array element having the character as an index has the value TRUE. If a character is not in the set, the array element has the value FALSE. Notice that the package uses a global SET_OF_CHAR variable called NULL_SET, which is initialized within the package and used in the function EMPTY_SET. Also notice, the code for the set operations INTERSECTION and MEMBER has been omitted.

Your Assignment:

Part 1: Write and add the code for the set operations INTERSECTION and MEMBER to the CHARSET package. Turn in a copy of the modified CHARSET package (containing the INTERSECTION and MEMBER operations).

Part 2: Modify the specification section of the CHARSET package so that SET_OF_CHAR is a private type. Recompile both the CHARSET package and the driver program, chardriv.adb. Explain why the driver program will not compile---turn in your explanation.

Part 3: Modify chardriv.adb to eliminate the compilation errors. Only a few lines of code should need to be changed. You will need to use set operations provided in the CHARSET package. Turn in a copy of the modified chardriv.adb.

Part 4: Modify the specification section of the CHARSET package so that SET_OF_CHAR is a limited private type. Again try to recompile the CHARSET package and the driver program, chardriv.adb. Explain why chardriv.adb will not compile---turn in your explanation.

Part 5: Add assignment and equality operators to the CHARSET package. Modify chardriv.adb to use these new operations; turn in the final version of the CHARSET package and the driver program, chardriv.adb.

Due Date: Oct 14 (This is the week of spring break so there are no Monday and Tuesday classes.)

How to compile Ada programs:

Before you can compile and link this program, you must create your "own" Ada library. Here are the suggested steps to follow:

  > mkdir adaprogs         .. create a directory to hold your Ada sources 
  > cd adaprogs            .. enter this directory

Next, create your Ada library as a subdirectory of your current directory (adaprogs), using the command

   > amklib adalib         .. create your Ada library

Note that the last step is "once-only". Now you can download your own copy of the Ada programs used in this assignment using the hyperlinks above. Finally, compile and link each program, for example chardriv.adb, as follows:

  > setenv ADALIB @adalib       .. set library "environment" variable
  > ada chardriv.adb            .. compile "unit" into your Ada library
  > ald -o chardriv chardriv    .. Ada linker, creates executable file

The order of compilation is important, compile charset.ads first, followed by charset.adb, and chardriv.adb last (do you know why?). Finally, all these incantations appear to work only on Tuxedo, so be sure that you are logged onto Tuxedo when you do this assignment.