Question: encrypt.cpp: #include #include #include encrypt.h / / Function to shift characters char shift _ char ( char c , int shift ) { if

encrypt.cpp:
#include #include #include "encrypt.h"// Function to shift characters char shift_char(char c, int shift){ if (c >='a' && c <='z'){ return 'a'+(((c -'a')+ shift +26)%26); } else if (c ==''){ return 'z'; // Encrypt space to 'z'} return c; }// Encrypt single char char encrypt(char c, int shift){ return shift_char(tolower(c), shift); }// Decrypt single char char decrypt(char c, int shift){ return shift_char(tolower(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: " : "decrypt: "); 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; }
main.cpp:
#include #include #include "encrypt.h" 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.
"; }} while (choice !='e' && choice !='d' && choice !='q'); return choice; } void get_opts(int &shift, char &dir){ cout << "Enter the direction of the shift (l/r): "; cin >> dir; cout << "Enter the shift number (integer): "; cin >> shift; std::cin.ignore(std::numeric_limits::max(),'
'); // Clear the input buffer }// Main program entry point. int main(){ char choice; do { choice = main_menu(); if (choice =='e'|| choice =='d'){ int shift; char dir; get_opts(shift, dir); process(choice, shift, dir); // Call process to perform encryption/decryption }} while (choice !='q'); std::cout << "Goodbye!
"; return 0; }
HOW TO FIX OUTPUT:
TO GET:
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

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!