------------------------------------------------------------------------------
MC logo
CSc 220 Assignment 3
[^] CSc 220 Programming Assignments
------------------------------------------------------------------------------

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

PNOUN: Smith Jones Ronald
NOUN: rock car tree snake pillow hose 
VI: ran fell tripped evaporated 
ADV: quickly nicely blithely 
ADJ: large small twisted logical       VT: threw scratched reduced 
     measured swallowed          VI: flew
--
PNOUN VT the ADJ NOUN across the NOUN.
The NOUN VI ADV down the NOUN.
Without the ADJ NOUN, PNOUN VI.
may produce
Jones scratched the logical pillow across the car.
The tree ran quickly down the hose.
Without the twisted rock, Ronald fell.
or possibly
Ronald swallowed the logical car across the hose.
The hose fell blithely down the car.
Without the twisted car, Ronald evaporated.

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.

You must read from standard input and write to standard output. Your program may not open any file.

When your program works, submit over the web here.
<<CSc 220 Assignment 2 CSc 220 Assignment 4>>