Starting from:
$35

$29

Program 2: Creating a Cryptogram Solution

Goals for P2



To write a program that includes a main program, a class de ned by the student.



To use and understand a template class and a standard C++ algorithm.



To understand how avector object grows and how to use it e ectively.



Before we can solve a cryptogram, we must be able to read it in from a le and store it. In the old days, we would use a character array of some xed size and hope that the data in the input le was short enough to t into that array. A more modern approach is to use an array that can be reallocated to be as long as necessary. C++ has a standard template class named vector that serves this purpose, and we will use vector in this project. By using code that you can see, I hope you will be able to understand what a template is and how an array can \grow".




Instructions.



2.1 Create the Cryptogram Class




De ne a C++ class named Crypto. This week the class will have just three data members, all objects of type vector<char. The rst will store the plaintext puzzle read in from a le. The second will be the encoded input message. The third will be the partially solved puzzle. More members will be added in P3.




The Crypto constructor must take the name of an plaintext input le (type string) as its rst parameter and a pointer to a Code object as its second parameter. Open the le and check for proper opening. Call fatal() and print an informative error message if the le does not open.




Then read one line of the le into your plaintext vector. Use string::getline(). Add a null terminator to the end of the line. This will become a puzzle to solve. Finally, process the plaintext one character at a time until the null terminator is found:




{ If the plaintext character is NOT a letter a..z or A..Z, push it into both the encoded message and the solution.




{ If the plaintext character IS a letter, convert it to upper case. Then look up the corresponding letter in the Code and push the coded letter into the encoded message. Push a corresponding underscore into the solution vector.




De ne a function to print the encoded message, then print the contents of your solution vector and nally a blank line.




2.2 The main program and testing.




In main, create a Code object and generate a code.




In main, create a Crypto object and print the message.




Use the le \p2.txt" as data. This will make it easy for both of us to check your results. Hand in source code for main, the Code and Cryptogram class, and your output.




Grading criteria will be similar to those for P1 (6 points total). Basically, they ask you to follow instructions, produce readable output, and use safe programming techniques and reasonable OO style.




As soon as you nish this project, start on P3.

CSCI 2226 Due Program 2: Creating a Cryptogram
2



2.3 Grading Criteria







Points Criteria (Total of 6 points)







Has a main program that follows instructions.



Follows directions in implementing the Crypto class, including the use of vectors.



De nes class Crypto with an .hpp le and a .cpp le.



Opens an input stream and checks for proper opening.



Reads, stores, and encodes the input according to instructions.



Prints the encoded message and the solution line in a neat and readable way.

More products