Question: encrypt.cpp and encrypt.h You should see the following functions declared in encrypt.h: void process ( char mode, int shift, char dir ) ; char encrypt

encrypt.cpp and encrypt.h
You should see the following functions declared in encrypt.h:
void process(char mode, int shift, char dir); char encrypt(char c, int shift); char decrypt(char c, int shift);
Do not modify encrypt.h, even when you add additional private functions to encrypt.cpp. Dont forget to #include the header (and any other libraries you might need, such as iostream) in your .cpp file!
process function
This function should be called from main.cpp as the entry point for the encryption/decryption functionality. It should:
Convert the shift and dir parameters to a single integer shift value (positive for right, negative for left)
Read characters one a time from cin and convert to lowercase
Encrypt or decrypt each character (based on the mode parameter, which should be e or d)
Write the result to cout
Hint: try reading the first character from the input stream (using cin.get()) before inserting the Result: message into the cout buffer. This will prevent Result: from being printed before waiting for the users input.
encrypt and decrypt functions
These functions should be called by the process function to encrypt or decrypt a single character. They should:
Take a character and an integer shift value
Use a combination of modulo and arithmetic to shift the character by the given amount
Handle the special case of the space character
Return the encrypted or decrypted character
Extra functions
You will likely discover some common functionality between encrypt and decrypt, and you may want to add helper functions to process as well. Define at least one additional private function in encrypt.cpp and call as needed.
Note: private functions are declared and defined in the .cpp file, but not the .h file. This means that they are only accessible within the same file (in this case, encrypt.cpp).
main.cpp
In addition to the one and only main function required in every C++ program, main.cpp declares two functions:
char main_menu(); void get_opts(int &shift, char &dir);
These functions should be defined after the main function in the same file.
main_menu function
This function should display the main menu (as shown in the sample runs ) and return the users choice. You may handle incorrect inputs here or in the main function, whichever makes more sense to you.
get_opts function
This function should prompt the user for the shift value and direction, storing the results in the passed-by-reference parameters shift and dir.
Note: while these will eventually be converted into a single signed integer in the process function, they are kept separate for ease of input and to have an excuse practicing with pass-by-reference parameters.
main function
Your main function should contain a loop that repeatedly displays the main menu, calls the appropriate functions based on the users choice, and exits when the user selects q. The logic should be something like:
Display the main menu and get the selected option
If the user selects quit, exit the program (stop looping)
If the user selects encrypt or decrypt:
Call get_opts to get the shift optionsPrompt for the phrase to encrypt/decryptCall process from the encrypt library
After each operation, display the main menu again
Incorrect choices (such as x) can be handled in the main function or in main_menu, whichever you prefer.
OUTPUT SHOULD LOOK LIKE:
Please select from the following options:
Encrypt (e)
Decrypt (d)
Quit (q)
Choice: d
Enter the direction of the shift (l/r): r
Enter the shift number (integer): 8
Enter the phrase to decrypt: mcmzfhlifhq hih xzqvstmhxizaf
Result: every day is a sprinkle party
Please select from the following options:
Encrypt (e)
Decrypt (d)
Quit (q)
Choice: e
Enter the direction of the shift (l/r): l
Enter the shift number (integer): 3
Enter the phrase to encrypt: CAPITAL LETTERS SHOULD BE CONVERTED TO LOWERCASE
Result: ymfqyixibqqbopxpelriaxzbx lksboqbaxqlxiltbo ypb
Please select from the following options:
Encrypt (e)
Decrypt (d)
Quit (q)
MORE EXAMPLES:
Please select from the following options:
Encrypt (e)
Decrypt (d)
Quit (q)
Choice: e
Enter the direction of the shift (l/r): l
Enter the shift number (integer): 3
Enter the phrase to encrypt: cats and dogs
Result: yqpxykaxaldp
Please select from the following options:
Encrypt (e)
Decrypt (d)
Quit (q)
Choice:
encrypt.cpp and encrypt.h You should see the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!