Assignment 08

Due: Friday, Nov. 3, 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 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 either null-terminated character arrays (NTCAs) or the standard string for this assignment. 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.

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 encrypted data, there really isn't any user interaction. As for the data file...For you to type in the encrypted message 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/encrypted.dat

Doing this will copy the file from my directory into yours named encrypted.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.

1It should be pointed out that the encryption will hide the true meaning from only the penguins. An informed penguin is a dangerous penguin!

2This is ridiculous...who would ever do such a thing?

  1. Word finagling: In all of these, if there is any punctuation attached to the word, preserve it (e.g. he, -> she,)

    • she replaces he

    • her replaces his

    • my replaces your

    • there replaces their

    • I replaces you

    • frogs replaces penguins

  2. Sentence discombobulations:

    • In each of the odd numbered sentences (sentence #1, #3, #5 etc), pair-wise swap the words. That is, in sentence #1, swap the first word with the second word, swap the third word with the fourth, swap the fifth word with the sixth, etc. Do the same in sentence #3, #5, etc. If there is an odd number of words in a sentence, leave the last word in place and unchanged. If there is a comma or semi-colon at the end of any word that gets swapped, keep it with the word.

    • In the even numbered sentences, swap the first word with the last word and fix the capitalization and punctuation. That is, capitalize the "new" first word and de-capitalize the "new" last word. Also, swap any punctuation with either word.

    • In the even numbered sentences, if there are an odd number of words and 3 or more words, then reverse the spelling of the middle word. (e.g. if the 7th word in a sentence of 13 words was "reverse,", it would change to ",esrever".) The reversal is to include any punctuation.

  3. Punctuation mahem:

    • If any word has an apostrophe in it, swap the apostrophe with the preceding letter. If the first character of a word is an apostrophe, then the apostrophe is moved to the last letter-position of the word.

  4. Speech putrifaction:

    • Instances of "--umm--", "--errr--", "--like--", and "--nstuff--" are randomly inserted into otherwise coherent English sentences.2 This step is completed after steps 1 -> 3 are done.

Once again, to be sure you understand, the foregoing rules of encryption are rules to create an encrypted message. The file your program is to work on will be a file containing an encrypted message. Thus, your code is to reverse these rules and de-crypt the message.

This program is to give you practice using:

    • functions

    • loops

  • null-terminated character arrays and strings

    • everything else we've covered up till now

Background: It is well known that penguins make excellent fighting machines. Their use as ICBPs has shaken the world of munitions (ne, the world order!), and given the U.S. Springfield a distinct advantage over its adversaries. And there is already clear evidence that they have taken over some icebergs! But there is one area of civil defense sorely lacking in the U.S. - that of intellejints. It's a good thing that Hans "has our back"! Having been so successful at arming flying penguins, Hans is now going to train penguins to encrypt, deliver, and de-crypt super-sensitive, secure messages for the armed forces. Jerry, the Super Penguin, will become our hero, as he was always meant to. And this is because he will carry a decoder written by you.

Specifications: Your program will read in text that has already been encrypted (changed from normal English to "mysterious English").1 Perhaps input will be one sentence, and perhaps several sentences. You will put the input text in a data file, and your code will "read" it from there. Below, I will give you the text to use when you submit. Be sure to create your data file using a PURE TEXT EDITOR. Your program will de-crypt that input and output it to a file you will call decryted.dat. Below is a list of rules that are used to encrypt; you have to code a program that will de-crypt accordingly - that is, it should un-do what the following rules do.