Question
Lang C++ Need help with Problem: write a program that asks the user for a string of characters and prints the encrypted message back to
Lang C++ Need help with Problem: write a program that asks the user for a string of characters and prints the encrypted message back to the user as a string of ASCII values in base 2 OR asks the user for a string of ASCII values in base 2 and prints the decrypted string of characters corresponding to those values back to the user. This program will use functions for converting numbers, getting input from the user, converting input from the user, and error checking. Ask the user if they want to encrypt a message entered as string of text or decrypt a message given as a string of ASCII characters in base 2. If the user wants to encrypt a message of text, then read a line of text that can include spaces, e.g. jen or jen mocello. o Print the users encrypted message back to the user in binary. If the user wants to decrypt a message of characters in binary, then read a string of 1s and 0s from the user. o Print the decrypted message in corresponding text. Continue to prompt the user for encrypting or decrypting until the user doesnt want to do this anymore
Print an error message when: The encrypted message (binary) cannot be separated into bytes The encrypted message (binary) isnt 1s and 0s Since our messages are in English, we are not using the extended ASCII chart (128-255). Make sure the binary numbers will produce characters within 0-127. Recover from the error by re-prompting the user for a new binary number after their error, until they give a good binary number. Example: Do you want to encrypt or decrypt a message: encrypt Enter the string to encrypt: jen 011010100110010101101110 Do you want to play again (yes or no)? yes Do you want to encrypt or decrypt a message: decrypt Enter the string to encrypt: 011010100110010101101110 jen Do you want to play again (yes or no)? no The idea is to keep each function, including main, to a maximum of 15 lines, and this does not include variable declarations, comments, curly braces, and blank lines.
(please include dealing with bad user inputs)
my code:
#include
#include
#include
#include
#include
using namespace std;
void bin_to_ascii() {
// function that takes a string of 1s and zeros as input and prints/returns binary string as ascii character
}
void ascii_to_bin() {
// function that takes an ascii character as input and print/returns the characer as binary value
}
void get_user_input(int &Input, string &vstring){
// function that gets the input from the user
cout << "Press 1 to enter a string and convert to binary or Press 2 to enter binary and convert to a string";
cin >> Input;
if (Input == 1) {
cout << "Please enter the string you would like to convert to ascii binary ";
getline(cin, vstring);
bin_to_ascii();
}
else if (Input == 2) {
cout << "Enter a binary to convert to string";
}
}
int main() {
int Inputtwo;
string Myinput;
get_user_input(Inputtwo, Myinput);
return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started