Roll Program Name: Roll.cpp XXXXXXXXXXInput File: roll.dat Kim and Pat like to text each other but are afraid that their parents might read their text messages. They have decided to write in code so...

1 answer below »
Roll
Program Name: Roll.cpp XXXXXXXXXXInput File: roll.dat
Kim and Pat like to text each other but are afraid that their parents might read their text messages. They have decided to write in code so their parents would not know what they are saying. They have developed a method for encoding their messages. The process for their code is:
· Put the message, including spaces, in the smallest square matrix that will hold the message. Fill cells in each row from left to right before moving to the next row. Rows and columns are numbered beginning with row one and column one as shown below.
· If there are unused cells at the end of the matrix, the first cell will be filled with an asterisk (*) and the remaining unused cells will be filled with consecutive letters of the alphabet beginning with the letter A and continuing until all empty cells have been filled.
· "Roll" the matrix to encode the message as follows:
· cells in a square with its left, uppermost cell having an odd numbered row and column (e.g. 1,1 or 3,3) will rotate each letter one cell clockwise around the square.
· cells in a square with its left, uppermost cell having an even numbered row and column (e.g. 2,2 or 4,4) will rotate each letter one cell counter-clockwise around the square.
· Rewrite the coded message in the new order by rows and send the coded message.
For example, the message I love Computer Science would fit into the 5x5 matrix shown at the left below and after the "Roll" the matrix would look like the matrix shown on the right below. All the cells in the square beginning with 1,1 have been rotated one position clockwise. All the cells in the square beginning with 2,2 have been rotated one cell counter-clockwise, etc.

1
2
3
4
5


1
2
3
4
5
1
I

L
O
V

1
E
I

L
O
2
E

C
O
M

2
P
C
O
E
V
3
P
U
T
E
R

3


T
I
M
4

S
C
I
E

4
N
U
S
C
R
5
N
C
E
*
A

5
C
E
*
A
E
The encoded message sent would be: EI LOPCOEV TIMNUSCRCE*AE
You are to write a program that will decode the encoded message.
Input
The first line of input will contain a single integer n that indicates the number of encoded messages to be sent. Each of the following n lines will contain a single encoded message with a perfect square number of characters less than 170 characters long.
Output
For each encoded message, you will print the decoded message. Do not include the characters used to fill the matrix.
Example Input File
2
EI LOPCOEV TIMNUSCRCE*AE
ITHEREE A G OS YEVSRR FORDON A THISO
Example Output to Screen
I LOVE COMPUTER SCIENCE
THERE IS A VERY GOOD REASON FOR THIS
Answered Same DayMay 13, 2021

Solution

Pulkit answered on May 14 2021
21 Votes

84103_c++/extra-lab-encoding-with-roll.docx

Roll
Program Name: Roll.cpp Input File: roll.dat
Kim and Pat like to text each other but are afraid that their parents might...

Submit New Assignment

Copy and Paste Your Assignment Here