C++代写: Assignment 5 Arrays Strings

 Assignment 5Arrays/ Strings
Grading: EVERY assignment in this course is graded by demoing your work for 10 minutes with a TA. You are required to meet with a TA within one week after the due date to demo. You are penalized for missing a scheduled appointment. In either case, if you submit late within 1 day (24 hours) of the deadline, you lose 10 points. if you submit late within 3 days of the deadline, then you lose 25 points. Your job is to convince the TA that your program works correctly, i.e. show your TA how to use/break your program.

1. You will create a program to encrypt messages. (50 points) You will create a program that uses Fractionated Morse code to encrypt and decrypt messages. Don’t Panic! You need know nothing about Morse code.

First you will read in a CDstring with the message to encode. Use this table to create an array of characters or string with each dot or dash as a separate character and Xs to indicate spaces. X between characters and XX between words.

Table 1: Morse code equivalents

You also get a keyword or phrase from the user. Create a function to remove duplicate letters. So beavers becomes beavrs. You will use it to fill in the first column of this table with the remainder of the alphabet filled in after the keyword:To encode “hello world” you first get the Morse code from table 1:

****X*X*D**X*D**XDDDXX*DDXDDDX*D*X*D**XD**XX

Divide (fractionate) them into groups of 3:
Then get the ciphertext for each column from table 2, as shown in red. If the last group only has Xs then you can ignore it.
So the encrypted message is BCQAV DLPNL HQAG. In telegraphic transmission we group them in 5 letter groups.

DESIGN CONSIDERATIONS
First, read the instructions carefully.

What do you need to do? You will read in a string of characters, including spaces. You must replace each character with its equivalent Morse code symbols (i.e. dots and dashes). You will use the 26Drow table 1 to do that. Remember to put in an X between letters and XX between words. You will take these symbols in groups of 3 to reference table 2. Each 3 symbols will be replaced by the letter indicated. Once you’ve done that then you display the resulting ciphertext to the screen.

The tables display individual characters for clarity of understanding. You may simplify your design by treating them as strings such as this for the first row of table 1:

This will create a 26 row by 2Dcolumn table. Create function that takes a single input character, looks up the Morse equivalent from the table and returns that string. Concatenate it onto the intermediate string.

You can do something similar to table 2. As you would be searching it by the string of symbols you might want the first row of that 26Drow table to look like this:

You will pull off 3 characters at a time from the intermediate string and look up the output ciphertext letter to concatenate to the output string. Write a function to take the 3Dcharacter string and return the ciphertext letter to concatenate to the output string. Remember you also need a function to take the key word or phrase entered by the user and strip duplicate letters before filling in table 2.
You will have a function to print the output ciphertext string. It will have a single parameter, which is the string. As it prints remember every sixth letter will be a blank space character to give the 5Dletter groups. The output will be all uppercase letters.
You will use CDStrings so review the string library. You will need to compare strings and stick 2

strings together.

HINT: Make your program case insensitive. Whichever way you convert the input create a function so you only need to write the code once. If you did this on a previous assignment then you do not need to write it again!

2. You will modify your program to decrypt messages. (15 points) To decrypt a message you reverse the process. You substitute for each ciphertext letter using the second table then decipher the symbols using the first table.
This will be similar using a lot of table lookup! You will convert each input ciphertext letter to the 3Dcharacter groups from table 2. Write a function that does the lookup. The input can be one letter at a time or the input string. HINT: After you convert each ciphertext letter you are finished with it! You can just remove it from the input string. Or you can just keep track of which ciphertext character is next in the input.
You will now have a string that contains dots, dashes, and Xs. Create a function to read the string. Save each character until you get to an X. Take the symbols and look up the plaintext letter in table 1. Add it to the output string. Skip or delete the X. Repeat. After you skip or delete the X if the next character is another X add a blank space to the output string and skip or delete that X.

When you get to the end of the ciphertext string you just need to print it to the user.

You will never enter or see the Morse code! You can use whatever symbols in place of dots and dashes you want internally.

KEEP IT SIMPLE: Morse cod includes numbers and some punctuation. You will not use them! Use short sentences for testing. Incremental development. Write your program and debug without a keyword. Just use a straight alphabet with table 2. Once you have the bugs worked out, save a copy of your program, then add the functions to read the keyword and write it to the table. When you do that how will you know if you already used a letter?

3. You will modify your program to increase the security. (5 points) If you look at the encryption table, table 2, low frequency letters at the end of the alphabet tend to be in the same place, which can make the security a tad bit weaker. How can you avoid this?

You can have the keyword start in some column other than the first column. Such as this:

This adds an offset to the keyword so you would also need to prompt for an offset of 1 to 25. Why don’t you need an offset of 26?

(10 pts) Program Style/Comments In your implementation, make sure that you include a program header in your program, in addition to proper indentation/spacing and other comments! Make sure you review the style guidelines for this class, and follow them, i.e. don’t align everything on the left or put everything on one line!

(10 pts) Design

Develop and document your design. Think about testing! Identify decision points where your flow of control may change (indicating a different logic path). If possible show how your design changed as you solved problems.

(10 pts) Testing Your test plan must cover all the logic paths through your program. Indicate which items failed the test and how you tested again. You will provide a test plan. Remember the test plan should be a table:

Input

Expected Output

Actual Output

Comments/explanation

You will be graded on how thorough your test plan is and how you used it to find and fix problems.
HINT: Your testing must include all rows and columns of both tables! And must include using different keywords.

HINT: Use functions to decompose your design and help make it readable. Several functions are already specified. Use others where appropriate. Remember that functions should be specific to a single task, which means they should be no more than around 15 lines of code. They can help with incremental development.

Electronically submit your C++ program and pdf, by the assignment due date, using TEACH.
**NOTE: The easiest way to upload your program from ENGR to TEACH is to map a network drive to your home directory on ENGR. Mac or Windows,

If you are doing this off campus, pay attention to the offScampus directions!!!!