Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AUTHOR: Phillip Viens
- //FILENAME: EncryptWord.cpp
- //DATE: 10/12/2017
- //REVISION HISTORY:
- //REFERENCES:EncryptWord.h
- //
- //Description: --Description for p2 class. For p2 I'll be using virtually
- //the same functionality as I did in P1 with the largest alterations taking
- //place in both the printStats and guessing methods. This is to incorperate
- //and test the functionality of the FindFault class.
- //First I will be repurposing the print stats method. Instead printing the
- //number of guesses and the highest and lowest guess. It will instead be
- //printing the number of right and wrong guesses the user input. Next we
- //will be changing the guessing method altogether. Instead of the user
- //guessing the value of the cipher shift the user will now be guessing
- //whether or not each index in the array has corrupt value or not.
- //For p2.cpp the user is brought through a series of prompts that tests
- //the functionality of the EncryptedWord class. Using a welcome function,
- //the programmer is presented with a short description including directions
- //of how to execute the functionality of the program. At this point the state
- //of the EncryptedWord class is toggled off. All of the statistics variables
- //in the EncryptedWord class are set to 0. Next using the enterWord function
- //the user is instructed to enter a string to be encrypted. Next the
- //cipherShift function generates an integer to be called by the setCipher
- //function in the EncryptedWord class. Once this process has executed the
- //state of the EncryptedWord class is now on and the guessCipher function
- //prompts the user to guess the integer generated in the guessShift function.
- //At this point the user is to continue following the onscreen directions
- //to enter an integer until the correct guess has been entered. During the on
- //state of the EncryptedWord class the tallyStats function is called repeatedly
- //keeping track of the continuous statistics of the game. This keeps track the
- //number of guesses, the highest guess by the user, the lowest guess by the
- //user, and the average number the user input in integers. Once the correct
- //integer has been guessed. A message congratulating the user on guessing
- //the correct is printed along with the decrypted word.
- //Next the The EncryptedWord function reset is called and the statistics
- //of the users guesses are set to 0 for the future games. The state of the
- //class is now reset and then set to off. The statistics are printed once again
- //to test the the reset function. It is the intent to show the functionality
- //of the EncryptWord class. In the implemention of the main driver I've clearly
- //output the the results of the ceasarShift to allow the programmer to test the
- //functionality of the program. This is for testing purposes. Ive also included
- //two extra objects for use incase there are other files that are need be
- //tested.
- //
- //Assumptions: For thesting driver it is assumed that the user will be
- //implementing tests using alphanumeric charachters and other characters.
- //The function does not read white space and will cut off before the next
- //string is read. The test will run if numbers are entered and
- //will give an output with an alphanumeric ascii value.
- //For guessing the the output of the cipherShift it is assumed that
- //only positive integers will be input by the user to guess. The program
- //will run if negative integers are input by the user but the statistics
- //will most likely not be correct. If anything besides an integer is put
- //in the input value game will have an infinitloop error and will crash.
- //This does include floating and double integers. It is also assumed that
- //the user will guess using a integer that is greater than 0. The program
- //will run if the integer is zero with no problem however it will skew
- //it will not be recorded as the lowest guess if that is infact true.
- //
- //Class Invariants:
- //Minimal: Stats hold a defualt value of zero. string word allows characters
- //from 0 to size up until the first whitespace. State of the EncryptWord class
- //is determined by whether or not a word is currently encrypted. reset is
- //called once cipherShift has been guessed.
- //Problematic: will encrypt numbers and characters to a alphanumeric number.
- //Unnecessary: users input on numberOfGuesses is not required.
- #include <iostream>
- #include "FindFault.h"
- using namespace std;
- int cipher; //value generated for user.
- int numberOfGuesses; //numberOfGuesses
- int numberOfWords; //numberOfWords.
- string play; //user input for game repeat.
- string word; //word entered by user.
- string guess; //Users input for guess
- char input; //input variable for the repeat function
- //Fucntional Prototypes
- void welcome();
- //description: This function displays a short hello message.
- //input: No user input.
- //processing: cout
- //output: Short welcome messaging describing guessing game
- //to user.
- void goodbye();
- //description: This function displays a short goodbye message.
- //input: No user input
- //processing: cout
- //output: short Goodbye message
- void printStats(EncryptWord &);
- //description: This function displays the games guessing statistics.
- //input: No user input
- //processing: statistical variables from the EncryptWord.cpp file.
- //output: final statistics of the guessing game.
- int amountOfWords();
- //
- //
- //
- //
- FindFault f(numberOfWords); //object for FindFault.
- EncryptWord e; //object for EncryptWord.
- string enterString();
- //description: This function displays a message telling the user to enter a
- //string of words for the EncryptWord class.
- //input: user is asked to input a string consisting of at least 5 characters.
- //processing: checks for a string of 5 characters or longs. Has the user try
- //again until process does not fail.
- //output: returns the value of the string. cout directions telling user to
- //input a word.
- void insertArray(string word, FindFault &);
- //description: This function inserts words from the given strings
- // into an array in the FindFault class
- //input: No input by the user
- //processing: Checks to see if there are any other words in the given
- //string and sets them in indexes in the Find Fault array
- //output: None.
- int cipherShift(EncryptWord &);
- //description: This function creates a random integer then using arithmetic.
- //takes the remainder of the integer divided by 10.
- //input: No user input. Input is a pseudo random number generated by c++.
- //processing: generates random number for cipher variable
- //output: returns a cipher variable for word encryption.
- bool guessCorrupt();
- //description: This function allows the user to perform queries on the
- //incorperated array from FindFault class. The user is asked to guess
- //whether or not the current string displayed is corrupt. Then the user
- //gives a yes or no guess which is then called by the isCorrupt function
- //in the FindFault class.
- //input: The user is asked to input a y or an n char for guessing purposes
- //processing: The input is determined and then called by the FindFault class
- //output: None.
- void printDecrypt(EncryptWord &);
- //description: This function displays a congratulatory message as well as the
- //result of the decrypted word.
- //input: No user input.
- //processing: decrypted word from EncrytWord.cpp
- //output: short congratulatory message along with the decrypted word.
- void printStats(FindFault &, EncryptWord &);
- //description: This function displays the games guessing statistics.
- //input: No user input
- //processing: statistical variables from the EncryptWord.cpp file.
- //output: final statistics of the guessing game.
- void printState(EncryptWord &);
- //description: This function displays the current state of the game.
- //On/Off.
- //input: No user input.
- //processing: Checks for a true or false flag from the EncryptWord.cpp file.
- //output: displays On or Off state of the game.
- int main()
- {
- welcome();
- amountOfWords();
- enterString();
- word = enterString();
- f.insert(word);
- f.getSize();
- f.getCapacity();
- f.getWord(0);
- /*do {
- printState(e);
- numberOfGuesses = 0;
- e.reset();
- amountOfWords();
- for (int i = 0; i < numberOfWords; i++) {
- enterString();
- word = enterString();
- f.insert(word);
- }
- guessCorrupt();
- printDecrypt(e);
- printState(e);
- printStats(f, e);
- e.reset();
- printState(e);
- printStats(f, e);
- cout << endl << "Would you like to play again (y=yes): ";
- cin >> play;
- input = char(int(play[0]));
- } while (input == 'Y' || input == 'y');
- goodbye();
- */
- return 0;
- }
- void welcome() {
- cout << endl << "Welcome to my Caesar Cipher!" << endl;
- cout << "In this project you will be given a series of instructions" << endl;
- cout << "First you will enter a sentence of words.";
- cout << "In this sentence each word needs to contain a minimum of" << endl;
- cout << "five letters." << endl;
- cout << endl << "Then the word will be shifted a certain number of letters";
- cout << endl << "Forward." << endl;
- cout << "Once that has been done the words well then go through" << endl;
- cout << "Another series of changes a some of them will be corrupted" << endl;
- cout << "Randomly." << endl;
- cout << "Once the word is presented to you it'll be your job to" << endl;
- cout << "guess if the word is corrupt or not!" << endl;
- cout << endl << "Feel free to play as many times as you'd like but remember";
- cout << endl << "If you are in a group take turns and have fun!";
- }
- void goodbye() {
- cout << endl << "Thanks for playing this super fun little";
- cout << endl << "guess game! Have a great day!";
- }
- int amountOfWords() {
- cout << "Please enter the number of words you'd like to encrypt: ";
- cin >> numberOfWords;
- cout << endl;
- FindFault f(numberOfWords);
- return numberOfWords;
- }
- string enterString() {
- cout << "Please enter a word containing 5 letters." << endl;
- cin >> word;
- if (word.length() < 5) {
- do {
- cout << "Please try again!" << endl;
- cin >> word;
- } while (word.length() < 5);
- }
- return word;
- }
- int cipherShift(EncryptWord &e) {
- cipher = rand() % 10 + 1;
- cout << endl << "The word has shiftedby: " << cipher << endl;
- //e.encrypt(word, cipher);
- //e.decrypt(word);
- e.getState();
- printState(e);
- cout << endl << "Your Word: " << word << endl;
- cout << "Your Word encrypted: " << e.getEncrypt() << endl << endl;
- return cipher;
- }
- void printStats(FindFault &f, EncryptWord &e) {
- cout << "Number of Guesses : " << e.getNumberOfGuesses() << endl;
- cout << "Number of Right Guesses: " << f.getRightGuess() << endl;
- cout << "Number of Wrong Guesses: " << f.getWrongGuess() << endl;
- }
- void printState(EncryptWord &e) {
- if (e.getState() == true)
- cout << "Current State: On" << endl;
- else
- cout << "Current State: Off" << endl;
- }
- void printDecrypt(EncryptWord &e) {
- cout << "Congatulations you guessed it!" << endl;
- cout << endl << "Here is the decrypted word: " << e.getDecrypt() << endl;
- cout << endl;
- }
- void insertArray(string word, FindFault &f) {
- f.insert(word);
- }
- bool guessCorrupt() {
- printState(e);
- cout << "The string has been encrypted but there seems to be an" << endl;
- cout << "error. Its now your job to go through the newly encrypted" << endl;
- cout << "words, and see if they are corrupt or not." << endl;
- printState(e);
- cout << endl;
- cout << e.getEncrypt() << endl;
- cout << "Has this word been corrupted(y= yes/ n = no): ";
- cin >> guess;
- return true;
- }
Add Comment
Please, Sign In to add comment