Guest User

Untitled

a guest
Oct 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.17 KB | None | 0 0
  1. //AUTHOR: Phillip Viens
  2. //FILENAME: EncryptWord.cpp
  3. //DATE: 10/12/2017
  4. //REVISION HISTORY:
  5. //REFERENCES:EncryptWord.h
  6. //
  7. //Description: --Description for p2 class. For p2 I'll be using virtually
  8. //the same functionality as I did in P1 with the largest alterations taking
  9. //place in both the printStats and guessing methods. This is to incorperate
  10. //and test the functionality of the FindFault class.
  11. //First I will be repurposing the print stats method. Instead printing the
  12. //number of guesses and the highest and lowest guess. It will instead be
  13. //printing the number of right and wrong guesses the user input. Next we
  14. //will be changing the guessing method altogether. Instead of the user
  15. //guessing the value of the cipher shift the user will now be guessing
  16. //whether or not each index in the array has corrupt value or not.
  17. //For p2.cpp the user is brought through a series of prompts that tests
  18. //the functionality of the EncryptedWord class. Using a welcome function,
  19. //the programmer is presented with a short description including directions
  20. //of how to execute the functionality of the program. At this point the state
  21. //of the EncryptedWord class is toggled off. All of the statistics variables
  22. //in the EncryptedWord class are set to 0. Next using the enterWord function
  23. //the user is instructed to enter a string to be encrypted. Next the
  24. //cipherShift function generates an integer to be called by the setCipher
  25. //function in the EncryptedWord class. Once this process has executed the
  26. //state of the EncryptedWord class is now on and the guessCipher function
  27. //prompts the user to guess the integer generated in the guessShift function.
  28. //At this point the user is to continue following the onscreen directions
  29. //to enter an integer until the correct guess has been entered. During the on
  30. //state of the EncryptedWord class the tallyStats function is called repeatedly
  31. //keeping track of the continuous statistics of the game. This keeps track the
  32. //number of guesses, the highest guess by the user, the lowest guess by the
  33. //user, and the average number the user input in integers. Once the correct
  34. //integer has been guessed. A message congratulating the user on guessing
  35. //the correct is printed along with the decrypted word.
  36. //Next the The EncryptedWord function reset is called and the statistics
  37. //of the users guesses are set to 0 for the future games. The state of the
  38. //class is now reset and then set to off. The statistics are printed once again
  39. //to test the the reset function. It is the intent to show the functionality
  40. //of the EncryptWord class. In the implemention of the main driver I've clearly
  41. //output the the results of the ceasarShift to allow the programmer to test the
  42. //functionality of the program. This is for testing purposes. Ive also included
  43. //two extra objects for use incase there are other files that are need be
  44. //tested.
  45. //
  46. //Assumptions: For thesting driver it is assumed that the user will be
  47. //implementing tests using alphanumeric charachters and other characters.
  48. //The function does not read white space and will cut off before the next
  49. //string is read. The test will run if numbers are entered and
  50. //will give an output with an alphanumeric ascii value.
  51. //For guessing the the output of the cipherShift it is assumed that
  52. //only positive integers will be input by the user to guess. The program
  53. //will run if negative integers are input by the user but the statistics
  54. //will most likely not be correct. If anything besides an integer is put
  55. //in the input value game will have an infinitloop error and will crash.
  56. //This does include floating and double integers. It is also assumed that
  57. //the user will guess using a integer that is greater than 0. The program
  58. //will run if the integer is zero with no problem however it will skew
  59. //it will not be recorded as the lowest guess if that is infact true.
  60. //
  61. //Class Invariants:
  62. //Minimal: Stats hold a defualt value of zero. string word allows characters
  63. //from 0 to size up until the first whitespace. State of the EncryptWord class
  64. //is determined by whether or not a word is currently encrypted. reset is
  65. //called once cipherShift has been guessed.
  66. //Problematic: will encrypt numbers and characters to a alphanumeric number.
  67. //Unnecessary: users input on numberOfGuesses is not required.
  68.  
  69. #include <iostream>
  70. #include "FindFault.h"
  71.  
  72. using namespace std;
  73.  
  74.  
  75. int cipher; //value generated for user.
  76. int numberOfGuesses; //numberOfGuesses
  77. int numberOfWords; //numberOfWords.
  78. string play; //user input for game repeat.
  79. string word; //word entered by user.
  80. string guess; //Users input for guess
  81. char input; //input variable for the repeat function
  82.  
  83.  
  84.  
  85. //Fucntional Prototypes
  86.  
  87. void welcome();
  88. //description: This function displays a short hello message.
  89. //input: No user input.
  90. //processing: cout
  91. //output: Short welcome messaging describing guessing game
  92. //to user.
  93.  
  94. void goodbye();
  95. //description: This function displays a short goodbye message.
  96. //input: No user input
  97. //processing: cout
  98. //output: short Goodbye message
  99.  
  100. void printStats(EncryptWord &);
  101. //description: This function displays the games guessing statistics.
  102. //input: No user input
  103. //processing: statistical variables from the EncryptWord.cpp file.
  104. //output: final statistics of the guessing game.
  105.  
  106. int amountOfWords();
  107. //
  108. //
  109. //
  110. //
  111.  
  112. FindFault f(numberOfWords); //object for FindFault.
  113. EncryptWord e; //object for EncryptWord.
  114.  
  115. string enterString();
  116. //description: This function displays a message telling the user to enter a
  117. //string of words for the EncryptWord class.
  118. //input: user is asked to input a string consisting of at least 5 characters.
  119. //processing: checks for a string of 5 characters or longs. Has the user try
  120. //again until process does not fail.
  121. //output: returns the value of the string. cout directions telling user to
  122. //input a word.
  123.  
  124. void insertArray(string word, FindFault &);
  125. //description: This function inserts words from the given strings
  126. // into an array in the FindFault class
  127. //input: No input by the user
  128. //processing: Checks to see if there are any other words in the given
  129. //string and sets them in indexes in the Find Fault array
  130. //output: None.
  131.  
  132. int cipherShift(EncryptWord &);
  133. //description: This function creates a random integer then using arithmetic.
  134. //takes the remainder of the integer divided by 10.
  135. //input: No user input. Input is a pseudo random number generated by c++.
  136. //processing: generates random number for cipher variable
  137. //output: returns a cipher variable for word encryption.
  138.  
  139. bool guessCorrupt();
  140. //description: This function allows the user to perform queries on the
  141. //incorperated array from FindFault class. The user is asked to guess
  142. //whether or not the current string displayed is corrupt. Then the user
  143. //gives a yes or no guess which is then called by the isCorrupt function
  144. //in the FindFault class.
  145. //input: The user is asked to input a y or an n char for guessing purposes
  146. //processing: The input is determined and then called by the FindFault class
  147. //output: None.
  148.  
  149. void printDecrypt(EncryptWord &);
  150. //description: This function displays a congratulatory message as well as the
  151. //result of the decrypted word.
  152. //input: No user input.
  153. //processing: decrypted word from EncrytWord.cpp
  154. //output: short congratulatory message along with the decrypted word.
  155.  
  156. void printStats(FindFault &, EncryptWord &);
  157. //description: This function displays the games guessing statistics.
  158. //input: No user input
  159. //processing: statistical variables from the EncryptWord.cpp file.
  160. //output: final statistics of the guessing game.
  161.  
  162.  
  163. void printState(EncryptWord &);
  164. //description: This function displays the current state of the game.
  165. //On/Off.
  166. //input: No user input.
  167. //processing: Checks for a true or false flag from the EncryptWord.cpp file.
  168. //output: displays On or Off state of the game.
  169.  
  170.  
  171.  
  172. int main()
  173. {
  174. welcome();
  175. amountOfWords();
  176. enterString();
  177. word = enterString();
  178. f.insert(word);
  179. f.getSize();
  180. f.getCapacity();
  181. f.getWord(0);
  182. /*do {
  183. printState(e);
  184. numberOfGuesses = 0;
  185. e.reset();
  186. amountOfWords();
  187. for (int i = 0; i < numberOfWords; i++) {
  188. enterString();
  189. word = enterString();
  190. f.insert(word);
  191.  
  192. }
  193.  
  194. guessCorrupt();
  195. printDecrypt(e);
  196. printState(e);
  197. printStats(f, e);
  198. e.reset();
  199. printState(e);
  200. printStats(f, e);
  201. cout << endl << "Would you like to play again (y=yes): ";
  202. cin >> play;
  203. input = char(int(play[0]));
  204. } while (input == 'Y' || input == 'y');
  205. goodbye();
  206. */
  207. return 0;
  208. }
  209.  
  210. void welcome() {
  211. cout << endl << "Welcome to my Caesar Cipher!" << endl;
  212. cout << "In this project you will be given a series of instructions" << endl;
  213. cout << "First you will enter a sentence of words.";
  214. cout << "In this sentence each word needs to contain a minimum of" << endl;
  215. cout << "five letters." << endl;
  216. cout << endl << "Then the word will be shifted a certain number of letters";
  217. cout << endl << "Forward." << endl;
  218. cout << "Once that has been done the words well then go through" << endl;
  219. cout << "Another series of changes a some of them will be corrupted" << endl;
  220. cout << "Randomly." << endl;
  221. cout << "Once the word is presented to you it'll be your job to" << endl;
  222. cout << "guess if the word is corrupt or not!" << endl;
  223. cout << endl << "Feel free to play as many times as you'd like but remember";
  224. cout << endl << "If you are in a group take turns and have fun!";
  225.  
  226. }
  227.  
  228. void goodbye() {
  229. cout << endl << "Thanks for playing this super fun little";
  230. cout << endl << "guess game! Have a great day!";
  231. }
  232.  
  233. int amountOfWords() {
  234. cout << "Please enter the number of words you'd like to encrypt: ";
  235. cin >> numberOfWords;
  236. cout << endl;
  237. FindFault f(numberOfWords);
  238. return numberOfWords;
  239. }
  240.  
  241. string enterString() {
  242. cout << "Please enter a word containing 5 letters." << endl;
  243. cin >> word;
  244. if (word.length() < 5) {
  245. do {
  246. cout << "Please try again!" << endl;
  247. cin >> word;
  248. } while (word.length() < 5);
  249. }
  250. return word;
  251. }
  252.  
  253. int cipherShift(EncryptWord &e) {
  254. cipher = rand() % 10 + 1;
  255. cout << endl << "The word has shiftedby: " << cipher << endl;
  256. //e.encrypt(word, cipher);
  257. //e.decrypt(word);
  258. e.getState();
  259. printState(e);
  260. cout << endl << "Your Word: " << word << endl;
  261. cout << "Your Word encrypted: " << e.getEncrypt() << endl << endl;
  262. return cipher;
  263. }
  264.  
  265.  
  266. void printStats(FindFault &f, EncryptWord &e) {
  267. cout << "Number of Guesses : " << e.getNumberOfGuesses() << endl;
  268. cout << "Number of Right Guesses: " << f.getRightGuess() << endl;
  269. cout << "Number of Wrong Guesses: " << f.getWrongGuess() << endl;
  270. }
  271.  
  272. void printState(EncryptWord &e) {
  273. if (e.getState() == true)
  274. cout << "Current State: On" << endl;
  275. else
  276. cout << "Current State: Off" << endl;
  277. }
  278.  
  279. void printDecrypt(EncryptWord &e) {
  280. cout << "Congatulations you guessed it!" << endl;
  281. cout << endl << "Here is the decrypted word: " << e.getDecrypt() << endl;
  282. cout << endl;
  283. }
  284.  
  285. void insertArray(string word, FindFault &f) {
  286. f.insert(word);
  287.  
  288. }
  289.  
  290. bool guessCorrupt() {
  291. printState(e);
  292. cout << "The string has been encrypted but there seems to be an" << endl;
  293. cout << "error. Its now your job to go through the newly encrypted" << endl;
  294. cout << "words, and see if they are corrupt or not." << endl;
  295. printState(e);
  296. cout << endl;
  297. cout << e.getEncrypt() << endl;
  298. cout << "Has this word been corrupted(y= yes/ n = no): ";
  299. cin >> guess;
  300. return true;
  301. }
Add Comment
Please, Sign In to add comment