Computers and Technology

The program in CombinationCipher. cpp takes a message written by the user and puts it through multiple ciphers. A cipher is a technique to create a secret code from a message. A combination cipher uses multiple ciphers to encode the same message. This combination cipher uses a Keyboard cipher twice and then uses Morse code. The Keyboard Code is just the order of letters your keyboard. The top row is the original letter, bottom row is the encoded letter.

The program in CombinationCipher. cpp file works, but it is ugly and harder to understand than it should be. That’s because it was written without functions other than main(). As a consequence, a lot of code gets repeated, and the overall logic of the program is hidden by the mass of details.
Rewrite the program by grouping the code into functions. Change the program so it takes the input from a file ‘input. txt’ instead of the terminal. In particular, your program should include the following functions:
1. A function named readInput that returns a string containing the message from a file. The parameter should be an fstream passed by reference.
A function named upperCase that returns nothing (void). The parameter should be one string containing the user entered message that gets modified to be all upper case letters. Hint: pass by reference.
A function named cipher that returns a string containing the fully encoded message. The parameter should be one string containing the uppercase user entered message.
A function named translateLetterKeyBoard that returns nothing (void). The parameter should be one char containing the letter to be modified, in accordance to the Keyboard cipher. Hint: pass by reference.
A function named translateLetterMorseCode that returns a string containing the char- acter in morse code. The parameter should be one char containing the letter to be translated, in accordance to Morse code.
A function named printOutput that returns nothing (void). The parameters should be two strings, the original user entered message and the final encoded message. This function should print the output.
As you introduce each function, replace the code in main() by calls to your new functions as appro- priate. In particular, note that some of these new functions may be called from within the bodies of some of the other functions.
Remember that this program was already working. You should not alter the output of the program in any way.
Hopefully, once you are done it will be obvious to you that your revised code is simpler and easier to understand than the original. In real life, code that is easier to understand, is easier to get working in the first place, so you should try to develop the code in small, function-based chunks from the very beginning.
To test your code you can always run inputs through the original .cpp and your own to compare the outputs.
Sample output of Task:
input. cpp:
#include
#include
using namespace std;
int main()
{
cout << "Assignment 0- Combination Cipher\n";
//Prompt the user for a string
string userInput ="";
cout << "Enter the string you would like encoded: ";
getline(cin, userInput);
string tempMessage =userInput;
//clean up the message and make all upper case
for(int i = 0; i < tempMessage. size(); i++)
tempMessage[i] = toupper(tempMessage[i]);
//Encode the message through KeyBoard Cipher
for(int i = 0; i < tempMessage. size(); i++){
char letter = tempMessage[i];
switch (letter){
case 'A':
letter = 'Q';
break;
case 'B':
letter = 'W';
break;
case 'C':
letter = 'E';
break;
case 'D':
letter = 'R';
break;
case 'E':
letter = 'T';
break;
case 'F':
letter = 'Y';
break;
case 'G':
letter = 'U';
break;
case 'H':
letter = 'I';
break;
case 'I':
letter = 'O';
break;

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:00, willowcollins3753
Write a program that uses a widgetviewer object to do the following: generate two random integers between 1 and 9 (inclusive). name one of them x, the other y. display them to the user using jlabel objects. create a jlabel object displaying the text "enter an operation number." create a jtextfield for the user's input. create a jbutton displaying the text "press here when you've entered your operation." use addandwait to add it to the widgetviewer object. when the user clicks the jbutton, evaluate operation in the following order to determine the one and only mathematical operation to perform on x and y. use a jlabel to display the result. if operation is between 1 and 10 inclusive, add x and y. if operation is evenly divisible by 4, subtract y from x. if operation is evenly divisible by 5, use integer division to divide y into x. if operation is an even number, use floating point division to divide y into x. if none of the other tests on operation apply, multiply x and y. note: operation can be negative or zero.
Answers: 2
image
Computers and Technology, 22.06.2019 11:00, ed72018373
Which law requires employers to provide safe working environments for their employees? a. civil rights act b. fair labor standards act c. occupational safety and health act d. wagner act
Answers: 1
image
Computers and Technology, 23.06.2019 09:30, rscvsdfsrysas3712
Why is an outfitting a workspace with video games in a technology development company considered a strategic use of money
Answers: 1
image
Computers and Technology, 24.06.2019 08:20, brinks7994
Which type of entity describes a fundamental business aspect of a database? a. linking b. lookup c. domain d. weak
Answers: 3
Do you know the correct answer?
The program in CombinationCipher. cpp takes a message written by the user and puts it through multip...

Questions in other subjects:

Konu
English, 18.02.2020 20:23