ITEC 320: Programming Assignment 4
Due 11:59:59 p.m. Friday, April 17, 2020

OPTIONAL: This assignment can only help your grade!

Submit Command: submit itec320-01 wordpkg.ads wordpkg-utilities.adb wordpkg-palindromes.adb more_pals.adb


Last modified:
Updates: You should now use this URL for the assignment checker: itec-noki01. The old one will disappear.

  1. 2020 Apr 13 10:20:30 AM: Set due date



This assignment involves wordpkg. Remember that a word is a contiguous sequence of non-whitespace characters. For this assignment there are several main parts:

  1. Modify wordpkg.ads to make it generic, adding a maximum word size as a parameter.

  2. Create a (generic) child package, called wordpkg.utilities. 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 enables checking the palindrome status (described below) of a word.

  4. Create a client that checks the palindrome status of several phrases (ie 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 packages/wordpkg-utilities.ads download, create the corresponding wordpkg.utilities implementation in wordpkg-utilities.adb.

  3. For the provided interface in packages/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 ranges 'a' .. 'z' and '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.utilities is
        function to_Upper(w: Word) return Word; 
        function remove_NonLetter(w: Word) return Word; 

        procedure to_Upper(w: in out Word); 
        procedure remove_NonLetter(w: in out Word); 
     end wordpkg.utilities;

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

Your client (named more_pals.adb) uses your packages to report the palindrome status (explained below) of zero or more phrases. You may end up not using all of the routines in WordPkg.Palindromes to complete the assignment but you are to implement them all anyway. You will, of course, also 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.

Standard 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 (eg file pals-in.txt):
 b    madamimadam   Madam-I-madaM  
madamImAdam       maDamI'maDam!

         !madam.I'm.Adam?  
    randomstring     

Reading from Standard Input and Output Produced:
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
Submit: Using the command shown above, 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-{utilities,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!

Other: See the the first assignment for information on creating data files, standard input, redirection, end of file for intereactive input, style, and the submit command.