Assignment 08

Due: Monday, April 10, 2017 at 12:00 p.m. 100 pts.

For this assignment you will submit (in the usual way) multiple files. These files will contain a C++ program that you have named appropriately, each file with an appropriate name and appropriate extension as well as input files to your program.

This program is to give you practice using:

    • functions

    • loops

  • null-terminated character arrays and strings

    • the system's random number generator

    • everything else we've covered up till now

Background: High-water pants are just too funny, so let's continue down that fashion path for hw 8. So, Milhouse is so enthralled with the success of his "flood pants", their design for utility and haute culture, that he really wants to push them on "Shark Tank", the TV venue whereby an entrepreneur tries to convince rich people to support his venture. To do this successfully, the candidate must speak with aplomb and grace and confidence. He must lay out a convincing argument for his potential benefactors to entice them to invest in the idea. Milhouse knows all this. He knows it well. He knows that he can't screw up. He must practice his speech. And that's where you come into the picture. You are going to write a program that will read in a speech that Milhouse might want to deliver, and mess it up royally so that Milhouse can see what he should not say while talking to a bunch of rich guys. So, your program will allow input of text (perhaps many sentences), and it will output the same speech but altered to emulate horrible grammar and sentence structure.

Specifications: Your program will read in text. Perhaps input will be one sentence, and perhaps several sentences. You will put the speech in a data file and your code will "read" it from there. Below, I will give you the speech to use when you submit. I will have to do that this week; in the meantime, write a data file with some sentences to test your code. Be sure to create your data file using a PURE TEXT EDITOR. Your program will output the effects of the following:

    1. Run on sentences - If there is more than one sentence, then you are to create from (only) the first two sentences, a run-on sentence. That is, you are to remove the punctuation ('.' or '!' or '?') from the first sentence, de-capitalize the first letter of the first word of the second sentence, and thus make it appear that the two sentences are just one sentence.

    2. If there are more than two sentences, then for the first sentence (after the second sentence of the input) that contains a comma, you will swap the part of that sentence before the comma with the part of that sentence after the comma. This you will apply to the first instance of a comma in a sentence. (So, if a sentence has more than one comma, you are only interested in the first comma.) For example, the sentence "After looking around, John, the undertaker, went home." would become "John, the undertaker, went home, after looking around."

    3. For all sentences of the input, including the sentences you applied parts 1 and 2 above to, you will apply the following 'word rules':

      1. With a 80% chance, replace any instance of

        • "is" with "are"

        • "isn't" with "ain't"

        • "has" with "have"

        • "she" with "her"

        • "he" with "him"

      2. Repeat any instance of "very". Thus "....very ...." would become "....very very ....."

      3. Any word ending in "ly" will have those two letters removed.

      4. Any word with more than 10 letters in it will be modified by inserting into the "middle" of it either "-umm-", "-err-", or "-uhh-". Your code will pick at random the 4th, 5th, 6th, or 7th letter, after which you will insert one of the above expressions. For example, the word "expeditionary" would become "expe-umm-ditionary".

    4. For the entire text, you will code so that the complete output will, with a 50% chance, begin with "I mean", and will end with "n'stuff" 70% of the time.

This is fair warning: this program is NOT easy. Get started early and think long and hard about how you will code this. Do not underestimate how long it will take.

Special Note: You are to use null-terminated character arrays (NTCAs) for this assignment, and not the standard strings. Think carefully how your code will read and handle the data. Remember that you have been taught how to read in char-by-char, word-by-word, and line-by-line. Also, you are allowed to work with a partner (encouraged) if you want. Only groups of two can make a coding team. Your partner must have the same cs 1570 instructor. Put both names on every file for this program. Submit under ONLY ONE NAME so that we print only one copy.

Have your code output the modified speech to the screen.

For this assignment you can assume the following:

  • no word is longer than 20 characters.

  • no sentence is longer than 500 characters.

  • the '.' and the '?' and the '!' will never be used but for to end a sentence. So, for example, you won't have to deal with "Dr. xxxx ..." and similar instances in your coding.

  • nothing about the total length of the text input.

  • there is only one space after a sentence-ending punctuation and the beginning of the next sentence (if it exists).

When you submit: Since you are welcome to hard code the connection of a file stream to a data file that contains the "speech", there really isn't any user interaction. As for the data file...For you to type in the speech would be odious (oooooh, I like that word). Thus, we are providing that file for you and a very simple way to "download" it. Create the directory where you are going to make your hw8 program, and then change to that directory. Then, at the unix prompt, type

wget http://web.mst.edu/~price/1570/speech.dat

Doing this will copy the file from my directory into yours named speech.dat. You'll see it when you issue the unix command ls. This will save you a LOT of time.

And, as usual, don't hesitate to ask any questions of your instructor if you have any.