Question: C + + program loops, conditionals, and functions Data types, particularly char and int Pass by reference parameters in C + + Buffered input and
C program
loops, conditionals, and functions
Data types, particularly char and int
Pass by reference parameters in C
Buffered input and output cin and cout
DO NOT USE arrays, vectors, strings, or any other data structure. The goal is to practice with the primitive data types and control structures in C
Sample Ciphers
Right shift of :
Plain text: hello world
Encrypted: khoorczruog
Left shift of :
Plain text: execute plan eagle at midnight
Encrypted: s ypo vkgwiv wbg vwovhdzidbco
Left shift of :
Plain text: the quick brown fox jumps over the lazy dog
Encrypted: qebxnrf hxzoltkxcluxgrjmpxlsboxqebxiywvxald
Sample runs of the program
Upon running your program, the user should see the following:
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Choice:
This main menu should be displayed after every operation, allowing for repeated encryptiondecryptions until the user chooses to quit.
Invalid choice
Any selection other than these three should result in an error message, with the prompt repeating until a valid selection is made. For example user input is underlined in bold:
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Choice: x
x is not a valid option, try again.
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Encrypt
If the user selects e the program should prompt the user for a shift value and direction and a message to encrypt. The encrypted message should then be displayed. For example:
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Choice: e
Enter the direction of the shift lr: l
Enter the shift number integer:
Enter the phrase to encrypt: cats and dogs
Result: yqpxykaxaldp
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Choice:
Decrypt
A lot like encrypt, but in reverse. Any phrases that you encrypt should be able to be decrypted back to the original message. For example:
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Choice: d
Enter the direction of the shift lr: l
Enter the shift number integer:
Enter the phrase to decrypt: yqpxykaxaldp
Result: cats and dogs
Please select from the following options:
Encrypt e
Decrypt d
Quit q
Quit
If the user selects q the program should exit without further prompting.
encrypt.cpp:
private functions
Define and use at least one useful private function
Public functions
Define and implement the functions declared in encrypt.h here.
encrypt.h:
Do not modify this header file.
#ifndef ENCRYPTH
#define ENCRYPTH
Process input according to the given parameters.
This function should read from cin and write to cout.
void processchar mode, int shift, char dir;
Encrypt a single character
Note that shift is negative for left, positive for right
char encryptchar c int shift;
Decrypt a single character
Note that shift is negative for left, positive for right
char decryptchar c int shift;
#endif ENCRYPTH
main.cpp:
#include
#include "encrypt.h
using namespace std;
Function declarations
Define these functions after main
Display the main menu and return the selected option
char mainmenu;
Prompt for and write to the desired shift and direction
void getoptsint &shift, char &dir;
int main
Main program entry point.
This function should:
Display the main menu and get the selected option
If the user selects quit, exit the progam stop looping
If user selects encrypt or decrypt:
Call getopts to get the shift options
Prompt for the phrase to encryptdecrypt
Call process from the encrypt library
After each operation, display the main menu
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
