Answer to Question #302053 in C++ for Zain

Question #302053

The tap code, sometimes called the knock code, is a way to encode text messages on a letter-by-letter basis in a very simple way. Tap code has been one of the most basic communication protocols and still used to convey SOS messages and other urgent communication. The tap code uses a 5×5 grid of letters representing all the English alphabets, see Figure 1. To communicate the word "water", the cipher would be the following (with the pause between each number in a pair being shorter (single space) than the pause between letters (two spaces)),


A B C/K D E

F G H I J

L M N O P

Q R S T U

V W X Y Z


Your task is to design a program that can

i) convert any given string into a Tap code sequence

Prototype: char* convertToTapCode(char*)

ii) and A Tap code sequence to a string (char*)

Prototype: char* convertToString(char*)


Note:

1) only use following library :

#include <iostream>



Note: however, you can use char*



helping link

http://yamm.finance/wiki/Tap_code.html


1
Expert's answer
2022-02-24T04:19:27-0500
using namespace std;

//Tap Codes
string StrToUpper(string s)
{
	int n;
	for(n=0;n<s.length();n++)
	{
		if(s[n]>='a' && s[n]<='z') s[n] = s[n]-32;
	}
	return(s);
}


void convertToTapCode(string s)
{
	char Letters[5][5]= 	{
								{'A','B','C','D','E'},
								{'F','G','H','I','J'},
								{'L','M','N','O','P'},
								{'Q','R','S','T','U'},
								{'V','W','X','Y','Z'}
							};
	int r,c,n;
	s = StrToUpper(s);
	cout<<"\nTap Code for "<<s<<" = ";
	for(n=0;n<s.length();n++)
	{
		for(r=0;r<5;r++)
		{
			for(c=0;c<5;c++)
			{
				if(s[n]=='K') s[n]= 'C';
				if(s[n]==Letters[r][c]) cout<<"("<<r+1<<", "<<c+1<<"), ";
			}
		}
	}
}


char convertToString(int x, int y)
{
	char Letters[5][5]= 	{
								{'A','B','C','D','E'},
								{'F','G','H','I','J'},
								{'L','M','N','O','P'},
								{'Q','R','S','T','U'},
								{'V','W','X','Y','Z'}
							};
	return(Letters[x-1][y-1]);
}


int main()
{
	string s = "Water";
	convertToTapCode(s);
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog