Question: FIX THE LOOP WHEN I TYPE: . / a 1 Please select from the following options: Encrypt ( e ) Decrypt ( d ) Quit

FIX THE LOOP WHEN I TYPE:
./a1
Please select from the following options:
Encrypt (e)
Decrypt (d)
Quit (q)
Choice: e Enter the direction of the shift (l/r): r
Enter the shift number (integer): 8
Enter the phrase to encrypt: every day is a sprinkle party
ALSO FIX THE OUTPUT SO IT MATCHES THE 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: d
Enter the direction of the shift (l/r): l
Enter the shift number (integer): 3
Enter the phrase to decrypt: yqpxykaxaldp
Result: cats and dogs
ENCRYPT.CPP:
#include
#include
#include
#include "encrypt.h"
// Function to shift characters\
char shift_char(char c, int shift){
if (c >='a' && c <='z'){
return static_cast('a'+(((c -'a')+ shift +26)%26));
} else if (c ==''){
return '';
}
return c;
}
// Encrypt single char \
char encrypt(char c, int shift){
return shift_char(c, shift);
}
// Decrypt single char \
char decrypt(char c, int shift){
return shift_char(c,-shift);
}
void process(char mode, int shift, char dir){
int effective_shift =(dir =='l')?-shift : shift;
std::string phrase;
std::cout << "Enter the phrase to "<<(mode =='e'? "encrypt: " : "decryp\
t: ");
std::getline(std::cin, phrase);
std::cout << "Result: ";
for (char c : phrase){
if (mode =='e'){
std::cout << encrypt(c, effective_shift);
} else {
std::cout << decrypt(c, effective_shift);
}
}
std::cout << std::endl;
}
// Define and use at least one useful private function
// Public functions
// Define and implement the functions declared in encrypt.h here.
MAIN.CPP:
#include
#include "encrypt.h"
#include
using namespace std;
// Function declarations \
char main_menu();
void get_opts(int &shift, char &dir);
// Display the main menu and return the selected option\
char main_menu(){
char choice;
do {
std::cout << "Please select from the following options:
";
std::cout << "Encrypt (e)
Decrypt (d)
Quit (q)
";
std::cout << "Choice: ";
cin >> choice;
if (choice !='e' && choice !='d' && choice !='q'){
std::cout << choice <<" is not a valid option, try again.
";

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!