Create C++ program.Convert this string to Tap Code using structures.
It is very important to use structures in this program.
The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C.
The listener only needs to discriminate the timing of the taps to isolate letters.
Each letter is communicated by tapping two numbers
For example, to specify the letter "B", one taps once, pauses, and then taps twice.
Or to communicate the word "water", the cipher would be the following (the pause between each number in a pair is smaller than the pause between letters):
| W | A | T | E | R |
|---|---|---|---|---|
|
5, 2 |
1, 1 |
4, 4 |
1, 5 |
4, 2 |
|
····· ·· |
· · |
···· ···· |
· ····· |
···· ·· |
The letter "X" is used to break up sentences, and "K" for acknowledgements.
Because of the difficulty and length of time required for specifying a single letter, prisoners often devise abbreviations and acronyms for common items or phrases, such as "GN" for Good night, or "GBU" for God bless you.[1]
By comparison, Morse code is harder to send by tapping or banging because it requires the ability either to create taps with a clear and precise rhythm or to produce two different-sounding noises. Morse code also takes longer to learn. Learning the Polybius square simply requires one to know the alphabet and the short sequence "AFLQV" (the initial letter of each row).
| Roman alphabet tap code | |||||
| 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
| 1 | A | B | C/K | D | E |
| 2 | F | G | H | I | J |
| 3 | L | M | N | O | P |
| 4 | Q | R | S | T | U |
| 5 | V | W | X | Y | Z |
| The tap code table | |||||
I have used hash table for this problem. When a string is given we try to obtain the pair of integers from the Roman alphabet tap code.
#include <iostream>
#include <string.h>
using namespace std;
// A structure for storing hash values based on the alphabets. It's corresponding row and column.
struct col{
char c;
int i;
int j;
};
void ans(char*);
int main() {
// your code goes here
char* input;
cout<<"Enter the string: ";
cin>>input;
ans(input);
return 0;
}
void ans(char* input)
{
col a[25];
a[0].c = 'A';
a[0].i = 1;
a[0].j = 1;
a[1].c = 'B';
a[1].i = 1;
a[1].j = 2;
a[2].c = 'C';
a[2].i = 1;
a[2].j = 3;
a[3].c = 'D';
a[3].i = 1;
a[3].j = 4;
a[4].c = 'E';
a[4].i = 1;
a[4].j = 5;
a[5].c = 'F';
a[5].i = 2;
a[5].j = 1;
a[6].c = 'G';
a[6].i = 2;
a[6].j = 2;
a[7].c = 'H';
a[7].i = 2;
a[7].j = 3;
a[8].c = 'I';
a[8].i = 2;
a[8].j = 4;
a[9].c = 'J';
a[9].i = 2;
a[9].j = 5;
a[10].c = 'L';
a[10].i = 3;
a[10].j = 1;
a[11].c = 'M';
a[11].i = 3;
a[11].j = 2;
a[12].c = 'N';
a[12].i = 3;
a[12].j = 3;
a[13].c = 'O';
a[13].i = 3;
a[13].j = 4;
a[14].c = 'P';
a[14].i = 3;
a[14].j = 5;
a[15].c = 'Q';
a[15].i = 4;
a[15].j = 1;
a[16].c = 'R';
a[16].i = 4;
a[16].j = 2;
a[17].c = 'S';
a[17].i = 4;
a[17].j = 3;
a[18].c = 'T';
a[18].i = 4;
a[18].j = 4;
a[19].c = 'U';
a[19].i = 4;
a[19].j = 5;
a[20].c = 'V';
a[20].i = 5;
a[20].j = 1;
a[21].c = 'W';
a[21].i = 5;
a[21].j = 2;
a[22].c = 'X';
a[22].i = 5;
a[22].j = 3;
a[23].c = 'Y';
a[23].i = 5;
a[23].j = 4;
a[24].c = 'Z';
a[24].i = 5;
a[24].j = 5;
int z,y,k=0,x;
while(strlen(input)) // until the length of the string
do the following
{
if(input[k]>='L')
x =
input[k]-65-2; // for the last three rows we have x to be ascii
value -65-2
else
x = input[k]-65-1; // else x will be ascii value -65-1
z = a[x].i;
y = a[x].j;
cout<<a[x].c<<" =
"<<z<<","<<y;
k++;
}
}
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters repr...
Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...