50 pts |
Yet More Madness |
Due: Oct. 29 |
A madlib is a simple game popular with children of reading age. The puzzle is a small paragraph with blanks marked with some part of speech. The child asks any available friends or family members for words in those categories and fills in the story, which they always find hilarious. (It's wonderful to be so easily delighted.) This program is a bit like that. The input file has two parts. The first specifies words in various parts of speech, and the second is text in which you place the words, chosen at random. The two parts are separated by the symbol -- (two dashes). For instance, the input
The first section consists of a series of part designators followed by words which belong to that part of speech. The legal designators are PNOUN:, NOUN:, VT:, VI:, ADV: and ADJ:. Any word following one of these designators is added to the list of words under that part. The designators stand for proper noun, noun, transitive verb, intransitive verb, adverb and adjective. Regular words must be non-blank and may not end in a colon. Line breaks may appear anywhere in this section; just read it as a series of words.
The sections are separated by -- on a line by itself. The second section begins after that line.
The second section differs in that line breaks must be preserved. Copy it from input to output, substituting each occurrence of any of the designators (without colons), PNOUN, NOUN, VT, VI, ADV or ADJ, with a word from the proper list chosen at random. (Of course, PNOUN is never a plain P followed by NOUN.) If the list for some designator is empty, leave the designator in the text.
You may write in either plain C or C++. (If you're sane, you'll use C++.) In C++, you may find the getline function useful for the second part, since it will read the input one line at a time. In plain C, you may want to use gets or fgets. Useful C++ string member functions are find and replace. In C, the strstr function might be useful.
When your program works, submit over the web here.
| CSc 220 Assignment 4 |