Cylon says what?!?!?! Part 1
Admiral Adama needs to decrypt a series of messages from his various lookout pilots. He’s hoping that one of them will let him know the position of the Cylon fleet. Because of his standing order, computers cannot be networked together, so to decrypt the message it will have to be run through 3 separate programs run on 3 different computers.
Adama feeds the encrypted file into the first computer, and it immediately spits out a new file. Looking at it he can see that it’s starting to decrypt the file.
He then feeds this new file into the second computer, and it immediately spits out a second new file. Looking at this file he can see that the file is almost readable, but still needs to go through the next stage.
Finally, Adama feeds the file to the last computer. It immediately spits out the final decrypted file and sees that one of his pilots has indeed found the Cylon fleet.
For this project you will be writing 3 programs. Each program will contain a main and 1 function that will do the decrypting.
Decryption stage 1:
Attached to this project is the initial file to decrypt. It is named one_message.txt. You will read the sentence into a string.
You will send the string to a function you write named “reverse_sentence”:
string reverse_sentence(string s);
This function will reverse the string, and then return the reversed string. Do not make a new string, save it back into the original string.
You must use one of the STL algorithms to reverse the string.
Write the string to a new file called “stage2.txt”.
Decryption stage 2:
The structure of this program is similar to stage 1; you will open the file “stage2.txt” and read the sentence into a string.
You will send the string to a function you write named “normalize_sentence”:
string normalize_sentence(string s);
This function will down case all letters of the string (that is, make all letters lower-case), and then up case only the first character of the string. It will then return the modified string.
You must use one of the STL algorithms.
Write out the normalized string to a new file called “stage3.txt”.
Decryption stage 3:
The structure of this program is similar to stage 2; you will open the file “stage3.txt” and read the sentence into a string.
You will send the string to a function called “replace_sentence”:
string replace_sentence(string s);
This function will replace certain words in the string with other words. You will then return the modified string.
You must use string functions.
USE IF-STATEMENTS TO DO THE SUBSTITUTIONS. DO NOT USE A SWITCH-STATEMENT IN THIS FUNCTION!!!
Here are the words that need to be replaced. Both words may appear once in the string.
- Replace “barn” with “Galactica”
- Replace “toaster” with “Cylon”
You must replace the entire string if you find these phrases
After you finish write out the string to a new file named “decrypted.txt”.
- You must close the files you are reading from and writing to before the end of each program.
- You can use cin/cout for testing, but remove or comment out the lines before turning in the program.
For stages 1 and 2, the functions required can be found in the algorithms section of the standard template library. You can see the library on http://www.cplusplus.com under the reference section.
Experiment. Write small test programs to test out functions before you build the full programs.
Note again that one_message.txt is attached.
- practice declaring C++ variables with appropriate names and data types
- practice console I/O
- practice using boolean expressions in flow-of-control statements
- learn and practice the strategy of incremental development
- your program source code must include your name and the project name in comments [5 points]
- your programs must compile and run without errors [15 points]
- your programs must successfully read from and write to text files 
reverse_sentence function implemented correctly 
normalize_sentence function implemented correctly 
replace_sentence function implemented correctly