Question

In: Computer Science

Actual Letter ABCDEFGHIJKLMNOPQRSTUVWXYZ Encrypted LetterBCDEFGHIJKLMNOPQRSTUVWXYZA Deliverables: Write a C++ program containing a menu which provides the...

Actual Letter ABCDEFGHIJKLMNOPQRSTUVWXYZ

Encrypted LetterBCDEFGHIJKLMNOPQRSTUVWXYZA

Deliverables: Write a C++ program containing a menu which provides the user with the following options and features:

1. Translate English Message in uppercase letters to an Encrypted Message

2. Translate Encrypted Message in uppercase letters back to an English Message

3. Quit.After translating, the user should be allowed to reselect another option from the menu. The program should keep running until the user decides to quit. Your code MUST match the sample outputs

provided in the following pages. Sample outputs, milestones and hints are on the following pages.Milestones1. Create a main() function which contains the menu and options for the user. The user should have three options:

1. Translate English Message to Encrypted Message

2. Translate Encrypted Message back to English Message

3. Quit

Remember, you can use loops and Boolean conditions to return an error and nag the user to enter the correct input. The entire main function should include a loop, allowing the user to keep translating or encoding images until the user decides to quit.

2. Declare two char arrays: one array which will hold the user’s message, and another array which will hold the output message (either the translated or encrypted version). The message size should be limited to 280 characters (the maximum size of a Twitter message). However, you never know when your boss or Twitter might change the maximum length, so it’s a good idea to declare a constant to specify your maximum message length rather than hard coding the length. You can set that constant equal to 280 for this assignment.

3. Remember, you should never assume your arrays are initialized. Remember to initialize them to zero or a dummy value before proceeding.

4. Use for loops to initialize, populate, encrypt and translate your secret messages. hint for loops which read, output, and input data to arrays.You should have the user enter zero as a flag variable to indicate the end of the message. You should have a counting variable to track the user’s message length to make it easier to output later (you don’t want to output all 280 available characters in the array if your user’s message is shorter than that). For simplicity, assume the message can only contain uppercase letters and no spaces, numbers, or special characters.If you need to encrypt or decode a message, one useful trick is to use static_cast. Each character (‘A, ‘B’, ‘C’ etc) has an integer value associated with it. For example, ‘A’ is 65, ‘B’ is 66, etc. We can use static_cast to easily increment our letters in the message in order to translate.oWhen encrypting, you want to replace the actual message with the next letter in the alphabet. You can use static cast to read the user’s message as an integer, increment the integer by 1, and then read that integer as the next letter in the alphabet:encryptedLetter = static_cast<char> (static_cast<int>(userMessage[count] + 1));oNote that for encoding letter Z, you need to set Z to A using an if statement or other means.

For translating an encrypted message back to English, the same approach can be

Solutions

Expert Solution

So, here is the solution for the given problem:

I am attaching screenshots also along with the code:

#include <iostream>

using namespace std;

const int MAX_SIZE = 280;

void encrypt();
void decrypt();

int main()
{

    while(true){
        cout<<"1. Translate English Message to Encrypted Message"<<endl<<"2. Translate Encrypted Message back to English Message"<<endl<<"3. Quit"<<endl;    
        int ch;
        cin>>ch;
        cin.ignore();
        switch(ch){
            case 1 : encrypt();
                    break;
            case 2 : decrypt();
                    break;
            case 3 : exit(0);
            default : cout<<"\nKindly enter a valid choice\n";
        }
    }
    
    return 0;
}


void encrypt(){
// for temporarily storing the string
    string temp;
    cin>>temp;

//taking minimum out of string length and MAX SIZE i.e 280
    int len = temp.length();
    if(MAX_SIZE<len)
        len = MAX_SIZE;

//taking two character array
    char user_msg[len] ,output_msg[len] = {'A'};
    for(int i = 0;i<len;i++){
        
        user_msg[i] = temp[i];

//if character is 0 that means this is the last character
        if(temp[i] == '0'){
            user_msg[i] = 0;
            output_msg[i] = 0;
            break;
        }
//if it is less than Z increament it
        else if(user_msg[i]<'Z')
            output_msg[i] = (char)((int)user_msg[i] + 1);
// else make character equal to A
        else
            output_msg[i] = 'A';
    }
    cout<<"Actual message was : "<<user_msg<<endl;
    cout<<"Encrypted message is : "<<output_msg<<endl;
}
void decrypt(){

//All remains same except the main loop logic
    string temp;
    cin>>temp;
    int len = temp.length();
    if(MAX_SIZE<len)
        len = MAX_SIZE;
    char user_msg[len] = {'A'},output_msg[len] = {'A'};
    for(int i = 0;i<len;i++){
        user_msg[i] = temp[i];
      if(temp[i] == '0'){
            user_msg[i] = 0;
            output_msg[i] = 0;
            break;
        }
//if it is greater than A decrement it
        else if(user_msg[i]>'A')
            output_msg[i] = (char)((int)user_msg[i] - 1);

//else make character equal to Z
        else
            output_msg[i] = 'Z';
    }
    cout<<"Encrypted message was : "<<user_msg<<endl;
    cout<<"Decrypted message is : "<<output_msg<<endl;
}

Here are the screenshots of all the functions used along with the output for your better understanding.

Output:

So, this was the solutions of the problem.

I hope I am able to solve your problem, if yes then do give it a like.

It really helps :)


Related Solutions

Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: ·...
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: · Your C++ source code file. (The file with the .CPP extension).No other files will be accepted. A screenshot of your program running. Program Instructions: Consider the following incomplete C++ program: #include int main() { … } 1. Write a statement that includes the header files fstream, string, and iomanip in this program. 2. Write statements that declare inFile to be an ifstream variable and...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside file there should be items: Open, Save, and Save As. Selecting open prompts the user to input a file name to a txt document containing employee information and displays a Jtable with the information, which can be edited. With column headers {"First Name" , "Last Name" , "Occupation" , "Office #"} Example: Gary Osbourn Teacher 113 Michelle Ramirez Teacher 101 Ava Gomez Principal 120...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Write a C/C++ program that simulate a menu based binary numbercalculator. This calculate shall have...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities:Covert a binary string to corresponding positive integersConvert a positive integer to its binary representationAdd two binary numbers, both numbers are represented as a string of 0s and 1sTo reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the following three functions:int binary_to_decimal(string...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu to choose from – 1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius 2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit 3. Quit. Formulae you will need: C = (5 / 9) * (F-32) and F = (9/5) * C + 32 1. Use functions to accomplish 1 and 2 above. 2. Use at least...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT