decode, C/C++ Programming

Assignment Help:
Problem Description
Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are sending their messages in a number format. This format represents the way that numbers and characters are padded on mobile’s keypad. One smuggler sends a text message to the second smuggler, using the numbers corresponding to the letters on the keypad. When the receiving smuggler gets the message, he simply opens the “create text message” function in his mobile and types the number string. This way the receiver finally reads the original message. For Example: - 6999066263304447777077766622337778 -----> message sent by the first smuggler. my name is robert---------> message decoded by the second smuggler. Where ‘0’ denotes the "space".

Explanation: By pressing ‘6’ (i.e. key’6’ one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area. By pressing ‘999’ (i.e. key ‘9’ three times) on the keypad, the mobile shows ‘y’ on display screen in write text message area. By pressing ‘0’ (i.e. key ’0’ one time) on the keypad, the mobile shows ‘space’ on display screen in write text message area. By pressing ‘66’ (i.e. key’6’ two times) on the keypad, the mobile shows ‘n’ on display screen in write text message area. By pressing ‘2’ (i.e. key ’2’ one time) on the keypad, the mobile shows ‘a’ on display screen in write text message area. By pressing ‘6’ (i.e. key ''6''one time) on the keypad, the mobile shows ‘m’ on display screen in write text message area. By pressing ‘33’ (i.e. key ‘3’ two times) on the keypad, the mobile shows ‘e’ on display screen in write text message area. By pressing ‘0’ (i.e. key ‘0’ one time) on the keypad, the mobile shows ‘space’ on display screen in write text message area. By pressing ‘444’ (i.e. key’4’ three times) on the keypad, the mobile shows ‘i’ on display screen in write text message area. By pressing ‘7777’ (i.e. key ’7’ four times) on the keypad, the mobile shows ‘s’ on display screen in write text message area. By pressing ‘0’ (i.e. key ‘0’ one time) on the keypad, the mobile shows ‘space’ on display screen in write text message area. By pressing ‘777’ (i.e. key ’7’ three times) on the keypad, the mobile shows ‘r’ on display screen in write text message area. By pressing ‘666’ (i.e. key ’6’ three times) on the keypad, the mobile shows ‘o’ on display screen in write text message area. By pressing ‘22’ (i.e. key ‘2’ two times) on the keypad, the mobile shows ‘b’ on display screen in write text message area. By pressing ‘33’ (i.e. key ‘3’ two times) on the keypad, the mobile shows ‘e’ on display screen in write text message area. By pressing ‘777’ (i.e. key ’7’ three times) on the keypad, the mobile shows ‘r’ on display screen in write text message area. By pressing ''8'' (i.e. key ’8’ one time) on the keypad, the mobile shows ‘t’ on display screen in write text message area.
But for word monkey 6#666#665533999 this string will be sent by the smuggler one Here ‘# ‘ denotes that if smuggler watches ‘#’ then it means character previous to # is on the same key to the character after the ‘#’ and smuggler has to wait for 2 seconds and then press the same key.
Explanation: By pressing ‘6’ i.e. key’6’ one time on the keypad, the mobile shows ‘m’ on display screen. For ''#'' wait for 2 seconds, and then press next. By pressing ‘666’ i.e. key’6’ three times on the keypad, the mobile shows ‘o’ on display screen. For ‘#’ wait for 2 seconds, and then press next. By pressing ‘66’ i.e. key’6’ two times on the keypad, the mobile shows ‘n’ on display screen. By pressing ‘55’ i.e. key’5’ two times on the keypad, the mobile shows ‘k’ on display screen. By pressing ‘33’ i.e. key’3’ two times on the keypad, the mobile shows ‘e’ on display screen. By pressing ‘999’ i.e. key’9’ three times on the keypad, the mobile shows ‘y’ on display screen.
*Here lower case doesn’t matter. *Assuming that the smuggler one will not send any numeral characters in the original message. For example smuggler will not send any message like "I need 1000 bucks" as it contains numerals. So policemen need your help to track the smugglers. You have to write a program that decodes the sending smuggler’s string (from the number format into plain text).

Related Discussions:- decode

Write a program for coupon redemption, The video game machines at your loca...

The video game machines at your local arcade output coupons depending on how well you played the game, you can redeem 10 coupons for a candy bar, 6 coupons for .a medium soft drink

Operators, write a program to accept ten numbers and display the total

write a program to accept ten numbers and display the total

Prepare an ipad application clash of clans like game, Prepare an iPad appli...

Prepare an iPad application Clash of Clans like game I would like to prepare a free city building app with the in app purchase possibility. An example game could be Clash of Cla

Example for register storage class - computer programming, Example for Regi...

Example for Register Storage Class - computer programming? main() { register int i; for (i=0; i { ............... ............... } } /* block exit will free the register

How the compiler arranges the several sections , Q: How the compiler arrang...

Q: How the compiler arranges the several sections in the executable image? A: The executable contained following sections: 1.      Data Section (initialized data variable sec

Program to define simulation method, This problem familiarizes you with usi...

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of π using a simulation method called "Monte Carlo". The following fi

Algorithm, Algorithm for railway ticket booking process

Algorithm for railway ticket booking process

C program to print l diagonal triangle, C program to print L diagonal trian...

C program to print L diagonal triangle: void main() {                 int i=0,j=0;                 int arr[rows][cols];                 for (i=0; i

Create a program of several prototypes for functions, In this assignment th...

In this assignment the main has been written for you in the file phone_book_main.cpp. You will also notice that a class called Person has been declared as having several prototypes

Write a program to illustrate array with strings, Write a Program to illust...

Write a Program to illustrate Array with Strings? main() { static char name[]="devdas"; int i; i=0; while(name[i]!='\0') { printf("%c",name[i]); i=i+1; } } In the

diana

9/4/2012 4:28:38 AM

Decode the Code

Solution :

#ifndef DECODE_H
#define DECODE_H

char *keys[] = {" ","","abc","def","ghi","jkl","mno","pqrs…
//int cyc[] = {1,0,3,3,3,3,3,4,3,4};

int count(char *ptr)
{
int i, cnt;
for(i=0;;i++)
{
if(*(ptr+i)!=(*ptr))
break;
}
return i;
}


char* decodeCode(char* encodedString)
{
char *decodedString;

int i,j,k,num;
char ch;

k=0;

decodedString = new char[512];
for(i=0;;)
{
ch = encodedString[i];
j = count(&encodedString[i]);

if(ch!=''#'' && ch!=''1'') {
num = ch - 0x30;
//num = num % cyc[];
decodedString[k] = keys[num][j-1];
decodedString[k+1] = ''\0'';
k++;
}

i = i +j;
if(i>(strlen(encodedString)-1))
break;
}

return decodedString;
}
#endif /* DECODE_H */



Question 2

Decode the Code
Problem Description
Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another.
In their new technology, they are sending their messages in a number format. This format represents the way that numbers and characters are padded on mobile''s keypad. One smuggler sends a text message to the second smuggler, using the numbers corresponding to the letters on the keypad. When the receiving smuggler gets the message, he simply opens the "create text message" function in his mobile and types the number string. This way the receiver finally reads the original message.
For Example: -
6999066263304447777077766622337778 -----> message sent by the first smuggler.
my name is robert---------> message decoded by the second smuggler.
Where ''0'' denotes the "space".

Explanation:
By pressing ''6'' (i.e. key''6'' one time) on the keypad, the mobile shows ''m'' on display screen in write text message area.
By pressing ''999'' (i.e. key ''9'' three times) on the keypad, the mobile shows ''y'' on display screen in write text message area.
By pressing ''0'' (i.e. key ''0'' one time) on the keypad, the mobile shows ''space'' on display screen in write text message area.
By pressing ''66'' (i.e. key''6'' two times) on the keypad, the mobile shows ''n'' on display screen in write text message area.
By pressing ''2'' (i.e. key ''2'' one time) on the keypad, the mobile shows ''a'' on display screen in write text message area.
By pressing ''6'' (i.e. key ''6''one time) on the keypad, the mobile shows ''m'' on display screen in write text message area.
By pressing ''33'' (i.e. key ''3'' two times) on the keypad, the mobile shows ''e'' on display screen in write text message area.
By pressing ''0'' (i.e. key ''0'' one time) on the keypad, the mobile shows ''space'' on display screen in write text message area.
By pressing ''444'' (i.e. key''4'' three times) on the keypad, the mobile shows ''i'' on display screen in write text message area.
By pressing ''7777'' (i.e. key ''7'' four times) on the keypad, the mobile shows ''s'' on display screen in write text message area.
By pressing ''0'' (i.e. key ''0'' one time) on the keypad, the mobile shows ''space'' on display screen in write text message area.
By pressing ''777'' (i.e. key ''7'' three times) on the keypad, the mobile shows ''r'' on display screen in write text message area.
By pressing ''666'' (i.e. key ''6'' three times) on the keypad, the mobile shows ''o'' on display screen in write text message area.
By pressing ''22'' (i.e. key ''2'' two times) on the keypad, the mobile shows ''b'' on display screen in write text message area.
By pressing ''33'' (i.e. key ''3'' two times) on the keypad, the mobile shows ''e'' on display screen in write text message area.
By pressing ''777'' (i.e. key ''7'' three times) on the keypad, the mobile shows ''r'' on display screen in write text message area.
By pressing ''8'' (i.e. key ''8'' one time) on the keypad, the mobile shows ''t'' on display screen in write text message area.
But for word monkey
6#666#665533999 this string will be sent by the smuggler one
Here ''# '' denotes that if smuggler watches ''#'' then it means character previous to # is on the same key to the character after the ''#'' and smuggler has to wait for 2 seconds and then press the same key.
Explanation:
By pressing ''6'' i.e. key''6'' one time on the keypad, the mobile shows ''m'' on display screen.
For ''#'' wait for 2 seconds, and then press next.
By pressing ''666'' i.e. key''6'' three times on the keypad, the mobile shows ''o'' on display screen.
For ''#'' wait for 2 seconds, and then press next.
By pressing ''66'' i.e. key''6'' two times on the keypad, the mobile shows ''n'' on display screen.
By pressing ''55'' i.e. key''5'' two times on the keypad, the mobile shows ''k'' on display screen.
By pressing ''33'' i.e. key''3'' two times on the keypad, the mobile shows ''e'' on display screen.
By pressing ''999'' i.e. key''9'' three times on the keypad, the mobile shows ''y'' on display screen.
*Here lower case doesn''t matter.
*Assuming that the smuggler one will not send any numeral characters in the original message. For example smuggler will not send any message like "I need 1000 bucks" as it contains numerals.

So policemen need your help to track the smugglers. You have to write a program that decodes the sending smuggler''s string (from the number format into plain text).
Instructions to work with Open PBT Client:

Specify the work directory path in the ''Work Directory Path'' field. The path should correspond to your solution project directory.
Download the support files by clicking the Get Dev Files.
You will find the following three folders:
bin
src
lib
in your work directory.
Code the solution in . java file inside the src folder
All required files will be downloaded to your work directory. Creating additional files is strongly discouraged.

Step 1:
In your solution file:

Implement your logic in public String decodeCode(String encodedString) in class DecodeTheCode.
String encodedString: is string which is send by the smuggler1.

You can create more methods but, do it in the same class.

Step 2:
In your solution keep in mind the following constraints.

In this problem you have to write a program that decodes the string, which is send by the first smuggler.
The method decodeCode() takes the string encodedString as an argument. That string is what the first smuggler sends to the second smuggler.
The method decodeCode() returns a string, which is the decoded string in plain text.
The string encodedString should only contain integers, and the special character ''#'' (if needed).
String encodedString should not contain any alphabetical characters (ex. ''a'', ''b''); otherwise return null
String encodedString should not contain any special characters, except ''#''; otherwise return null

The Prototype of the method is:
public String decodeCode(String encodedString).
This method takes following arguments.

String encodedString: represents the string which is sent by the smuggler1.

Method decodeCode() will return a string which is the decoded string of that string which is send by the smuggler1.

The constraints are:

String encodedString should have only integer and special character ''#'' (if needed).
String encodedString should not have any alphabetic character (ex. ''a'',''b'') else return null
String encodedString should not have any special character except ''#'' else return null
String encodedString is empty then returns null.

Example 1
Input :
String encodedString=6999066263304447777077766622337778
Output :
my name is robert

Explanation:
when you will type the given string in the mobile in create text message area then my name is robert message will be displayed.
Example 2
Input :
String encodedString=777733663084433072#222552433
Output :
send the package
Example 3
Input :
String encodedString=777733663T084L43m30;72#222552433

Output :
null
For Java solutions
Package Name : test.decodethecode
File Name : DecodeTheCode.java
Class Name : DecodeTheCode
Function Name : public String decodeCode(String encodedString)

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd