RU beehive logo ITEC dept promo banner
ITEC 320
2018fall
nokie
ibarland

generic and child packages
itec320 hw06 (pals)

Due: 2018-Nov-26-ish28 (Wed.) 15:00 23:59, D2L and hardcopy

Updates: ignoring formatting and minor phrasing changes

This assignment involves wordpkg. Remember that a word is a contiguous sequence of non-whitespace characters. For this assignment there are several main parts, each of which is described in more detail below:

  1. Modify wordpkg.ads to make it generic, adding a maximum word size as a parameter.
  2. Create a (generic) child package, called wordpkg.wordops. This package will contain routines that perform certain operations on a word.
  3. Create a (generic) child package, called wordpkg.palindromes. This package will contain a routine that enable checking the palindrome status (described below) of a word.
  4. Create a client that checks the palindrome status of several phrases (i.e. words).

Steps and files

Since we are dealing with a package and two child-packages (each with a .ads spec and .adb body), plus a driver: this program will have a total of seven files. Of the four provided files, only one should be modified:

  1. Modify the provided wordpkg.ads download to make it generic. The provided implementation wordpkg.adb download should not need any modification.
  2. For the provided interface in wordpkg-wordops.ads download, create the corresponding wordpkg.wordops implementation in wordpkg-wordops.adb.
  3. For the provided interface in wordpkg-palindromes.ads download, create the corresponding wordpkg.palindromes implementation in wordpkg-palindromes.adb.

These child packages are, and must be, generic, and you should review how to instantiate a child of a generic parent.

The operations to include in your child package are listed below. Notice the difference between the function and procedure versions of toUpper and removeNonLetter. For this assignment, letters are defined to be any Characters in the range 'a'..'z' or 'A'..'Z'; any other character is a non-letter. You might want to check out the package Ada.Characters.Handling as you work on the assignment. So that your code can be tested, make sure that you use the exact names listed below and the exact child package names. In other words, do not make any changes to this specification. Operations in the child packages are:

generic
package wordpkg.wordops is
   function  to_Upper(w: Word) return Word;
   procedure to_Upper(w: in out Word);

   function  remove_NonLetter(w: Word) return Word;
   procedure remove_NonLetter(w: in out Word);
end wordpkg.wordops;

generic package wordpkg.palindromes is function is_Pal(w: Word) return Boolean; end wordpkg.palindromes;

Your client (named pals.adb) uses your packages to report the palindrome status (explained below) of zero or more phrases. Your client code might not need every routine in the child packages to complete the overall task, but do implement them all anyway. You will, of course, want to test all of your routines!

Your client should call the get routine from wordpkg to read zero or more phrases from standard input. If a phrase is longer than the maximum word length, then your program should immediately print an appropriate error message and halt (but not crash) — that is, the client should handle the exception thrown from wordpkg.

Input

Your program should read from stdin, which will be a sequence of phrases, with any amount of white space allowed around any of the phrases. The phrases themselves will not contain white space, although they can contain non-letters. Your program should read from the input until it reaches end of file. Remember that get from the word package returns a word of length 0 at end of file. You should probably use this test rather than explicitly testing for end of file.

Output

Output will include the original string, its status, and, possibly, a modified string that is a palindrome. This output should be in the exact format that is shown in the sample run. The palindrome status of a string is the first of the following that applies:
  1. Palindrome as is
  2. Palindrome when non-letters are removed
  3. Palindrome when converted to upper case
  4. Palindrome when converted to upper case and non-letters are removed
  5. Never a palindrome

SAMPLE RUN

Sample Input
Your program will read from stdin, though for ease of testing, you might store this in a file pals-in.txt (and later use input-redirection):
 b    madamimadam   Madam-I-madaM
madamImAdam       maDamI'maDam!

         !madam.I'm.Adam?
    randomstring
Corresponding Output
Your program should print to stdout: rucs% pals < pals-in.txt String: b Status: Palindrome as is String: madamimadam Status: Palindrome as is String: Madam-I-madaM Status: Palindrome as is String: madamImAdam Status: Palindrome when converted to upper case PalStr: MADAMIMADAM String: maDamI'maDam! Status: Palindrome when non-letters are removed PalStr: maDamImaDam String: !madam.I'm.Adam? Status: Palindrome when converted to upper case and non-letters are removed PalStr: MADAMIMADAM String: randomstring Status: Never a palindrome

Submitting

On D2L, you will submit the files:

You do not need to submit the files we provided which don't need to be changed: wordpkg.adb, wordpkg-{wordops,palindromies}.ads. Note that when grading, I will be using your files along with the provided files, and your files really do need to compile with those!


logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.