home—lectures—textbook—exams—hws—D2L—breeze (snow day)
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
- Nov.26 16:00: extend due-date 9h, by popular demand.
- Nov.25 17:27: Firm up deadline to Wed. class; belatedly remove “draft”.
- Nov.25 16:39: remove redundant methods/ops from WordPkg-Palindromes.ads.
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:
- Modify wordpkg.ads to make it generic, adding a maximum word size as a parameter.
- Create a (generic) child package, called wordpkg.wordops. This package will
contain routines that perform certain operations on a word.
- 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.
- 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:
- Modify the provided wordpkg.ads download to make it generic.
The provided implementation wordpkg.adb download should not need any modification.
- For the provided interface in wordpkg-wordops.ads download,
create the corresponding wordpkg.wordops implementation in wordpkg-wordops.adb.
- 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:
- Palindrome as is
- Palindrome when non-letters are removed
- Palindrome when converted to upper case
- Palindrome when converted to upper case and non-letters are removed
- 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:
- wordpkg.ads (modified to be generic)
- wordpkg-wordops.adb, with general-purpose word operations
- wordpkg-palindromes.adb, with palindrome-specific word function
- pals.adb, your client. This is the only file that should call I/O routines.
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!
home—lectures—textbook—exams—hws—D2L—breeze (snow day)
 This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland radford.edu |
 |