Instructor's Manual for
M.B. Feldman and E.B. Koffman, Ada 95 Problem Solving and Program Design, 3rd edition. Copyright 1999, Addison-Wesley Publishing Company. All Rights Reserved
Questions and comments to mfeldman@seas.gwu.edu
last revised March 1999
The student will
string slicing |
string concatenation |
cryptogram |
character mapping |
end of file marker |
end of line marker |
text file redirection |
histogram |
Ada 83's predefined support for strings provided only a baseline set of operations: assignment, comparison, concatenation, and slicing. In Ada 95, these primitives are retained, and augmented by a set of very powerful standard library packages. While detailed coverage of these is beyond the scope of this text, some of the facilities are surveyed in Section 10.2.
Students have difficulty understanding why a character variable is not compatible with a 1-character string. Another source of problems is string assignment, because the programmer must contrive that the string lengths be equal on both sides of the assignment. This can be done with slicing; give some examples. Mention that more general string facilities are provided in the standard libraries; refer interested or experienced students to the Ada 95 Reference Manual (on the CD-ROM or elsewhere).
Program 10.1 shows a cryptogram generator using the predefined operations; this is interesting to compare with Program 10.2, which uses operations from the new standard libraries.
Compare Programs 10.1 and 10.2. Discuss character mappings and how they can be used to produce cryptograms and other translations more simply than using table lookup.
This section examines files systematically.
Plan to spend some time examining the file copy program 10.3 in detail, especially the use of End_Of_Line and End_Of_File. The interaction between input of characters and strings, on the one hand, and numeric and enumeration tokens, on the other, is not obvious, and so the details of the various Gets should be studied closely, with special emphasis on the circumstances in which "white space" is or is not skipped. Students often run into trouble and unexpected results when they intermix Gets and Get_Lines.
This section introduces the concept of input and output redirection as supported in UNIX and MS-DOS The histogram plotter is a "fun" case study, especially in its use of screen-control operations.
Compare the three kinds of input and output: from and to standard files, named files, and strings. Point out that string tokens are converted to and from their numeric and enumeration equivalents even when IO is to and from a string; these versions of Get and Put, which were available in Ada 83, seem to be little known even by Ada enthusiasts.