Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this lab, you are tasked with writing a program to encode and decode message

ID: 3566644 • Letter: F

Question

For this lab, you are tasked with writing a program to encode and decode messages using a 5x5 grid
cipher, shown here:
--1 2 3 4 5
1 a b c d e
2 f g h i j
3 k l m n o
4 p q r s t
5 u v w x y
Your program will allow the user 3 options, to encode a message, to decode a message, or to exit the
program. This message should be printed in a menu. If the user does not select one of these options,
inform the user that they selected an invalid option, print the menu, and wait for the user to input
something. If the user selects encode, then ask for a word to be encoded. Your program will then print
out the encoded message. If the user selects decode, then ask for the numbers to decode. Your program
will then print out the decoded message.
Your task is to :
? Use 3 functions, PrintMenu, Encode, and Decode. The type of function is up to you.
? Use a switch case when converting from letters to numbers and vice versa.
? Use loops. If you can use a for loop, please try to do so (not required).
Notes:
? The letter 'z' will be counted as an 's'
? The 26 switch statement is provided for you on my website, below the lab description.

Sample Output:
Please select one of the following:
1. Encode a sentence
2. Decode a sentence
3. Quit
1
Please enter the word you would like to encode:
hello
The encoded message is: 2315323235
Please select one of the following:
1. Encode a sentence
2. Decode a sentence
3. Quit
2
Please enter the encoded message to decode:
2315323225
The decoded message is:
hellj
Please select one of the following:
1. Encode a sentence
2. Decode a sentence
3. Quit
4
Invalid choice. Please select another:
Please select one of the following:
1. Encode a sentence
2. Decode a sentence
3. Quit
3
Program Terminating.
BONUS!!! (Worth 20 Points!!!)
Right now, the requirement is that your code will be able to handle a single word. Make your program
more general so that it is able to handle sentences with spaces, punctuation, and upper case letters.
Similarly, it should be able to decode sentences with spaces and punctuation.

Explanation / Answer

#include #include using namespace std; class playfair { public: void doIt( string k, string t, bool ij, bool e ) { createGrid( k, ij ); getTextReady( t, ij, e ); if( e ) doIt( 1 ); else doIt( -1 ); display(); } private: void doIt( int dir ) { int a, b, c, d; string ntxt; for( string::const_iterator ti = _txt.begin(); ti != _txt.end(); ti++ ) { if( getCharPos( *ti++, a, b ) ) if( getCharPos( *ti, c, d ) ) { if( a == c ) { ntxt += getChar( a, b + dir ); ntxt += getChar( c, d + dir ); } else if( b == d ){ ntxt += getChar( a + dir, b ); ntxt += getChar( c + dir, d ); } else { ntxt += getChar( c, b ); ntxt += getChar( a, d ); } } } _txt = ntxt; } void display() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote