Project #3
Computer Science 261
Due Wednesday, Oct 31, 2001
Cryptoquote is a popular game that
appears in many newspapers. A statement
by some notable person is encoded using a simple substitution code. The encoded quote is printed in the newspaper
and the reader is supposed to figure out what the original quote is. For example, the quote
IF YOU CAN’T STAND THE HEAT, GET OUT OF THE
KITCHEN.
might
be encoded as
RJ EMK DPS’W HWPSY WQG QGPW,
OGW MKW MJ WQG ZRWDQGS.
where every I is replaced by R, every F is replaced by J, and so on. Seeing the word DPS’W, the player might guess that W represents either S or T. Seeing the word WQG repeated and suspecting that W is T, he might guess that this is the word THE. If he makes enough correct guesses, then the rest of the pieces will fall into place.
Write a C++ program that will let the user (player) choose which of 25 puzzles to solve. The program will read a statement from a file named Quotes.txt. Then the program will create a random permutation of the letters of the alphabet and use this permutation to encode the statement. The encoded version will be displayed. Underneath the encoded version will be printed a copy of the puzzle where the letters are replaced by underscores. For example, the program might print
RJ EMK DPS’W HWPSY WQG QGPW,
OGW MKW MJ WQG ZRWDQGS.
__ ___ ___’_ _____ ___ ____, ___ ___ __
___ _______.
Notice that punctuation is not encoded.
As the player makes guesses, the underscores will be replaced by his guesses. After making the guesses described above (W ® T, Q ® H, G ® E), the puzzle will look like this:
RJ EMK DPS’W HWPSY WQG QGPW,
OGW MKW MJ WQG ZRWDQGS.
__ ___ ___’T _T___ THE
HE_T, _ET __T __ THE __T_HE_.
For each guess, the program will prompt the player to enter the letter to change. After the user enters that letter, it will prompt him for the letter to change it to. After entering that letter, the program will print the updated puzzle and continue. The user may enter each letter in either uppercase or lowercase; the output will be in uppercase. If the player enters a question mark (?) instead of a letter, then the program will print the answer and quit.
The program should use the following functions:
1. GetQuote() – This function will use an int parameter to indicate which puzzle is to be used. The function should open a file named Quotes.txt. This file contains 25 quotes. The function should read and return the quote indicated by the parameter.
2. toupper() – This function will have one string parameter. It will convert the string to uppercase and return the uppercase version. Note that this function overloads the library function toupper() which converts a char to uppercase.
3. Permute() – This function will permute the letters of the alphabet and return the permuted letters as a string. The string will later be used to encode the statement.
4. Encode() – This function will use the permuted alphabet to encode the text of the statement that was read from the file. For example, if the permuted alphabet begins "RHN...", then every A in the statement should be replaced with R, every B with H, every C with N, and so on.
5. FillUnderscores() – This function will return a copy of the encoded string with the letters replaced with underscores.
6. ChangeLetter() – This function will fill in the guessed letter for every occurrence of the corresponding letter in the puzzle.
7. DisplayPuzzle() – This function will display the encoded statement and the line of underscores and letters that have been guessed so far.
Some of these functions have been written for you. They can be found in the file Functions.cpp.
Place the program Cryptoquote.cpp in a folder named Project 3 and drag it to the dropbox.