in C++
Description
The purpose of this challenge is to manually manipulate character arrays. This challenge converts text in phone numbers to their equivalent values on a phone keypad.
Requirements
Write a program to decode phone numbers with letters in them.
Create a void function decodetext(char after[], char before[]). This function should be case-insensitive. Do NOT cout in this function.
Declare a char array to hold a maximum of 50 characters.
Ask the user to enter a string. Use cin.getline(char_variable, 50) function call to get the string from the user.
Make sure to ignore (don’t decode) dashes in the string.
Show the decoded phone number
You may need to write other functions to make your code easier. It’s up to you.
Sample Interaction / Output
Enter a phone number: 800-555-HELP 800-555-HELP is actually 800-555-4357 Enter a phone number: ABC-DEF-GHI-JKL-MNO-PQRS-TUV-WXYZ ABC-DEF-GHI-JKL-MNO-PQRS-TUV-WXYZ is actually 222-333-444-555-666-7777-888-9999
Here is the code for you:
#include <iostream>
using namespace std;
void decodetext(char after[], char before[])
{
int i;
for(i = 0; before[i] != '\0'; i++)
{
char ch = before[i];
switch(ch)
{
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c': after[i] = '2'; break;
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f': after[i] = '3';
break;
case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i': after[i] = '4';
break;
case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l': after[i] = '5';
break;
case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o': after[i] = '6';
break;
case 'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's': after[i] = '7';
break;
case 'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v': after[i] = '8';
break;
case 'W':
case 'w':
case 'X':
case 'x':
case 'Y':
case 'y':
case 'Z':
case 'z': after[i] = '9';
break;
default : after[i] =
ch;
}
}
after[i] = '\0';
}
int main()
{
char before[50], after[50];
cout << "Enter a phone number: ";
cin.getline(before, 50);
decodetext(after, before);
cout << before << " is actually "
<< after << endl;
}
And the output screenshot is:
in C++ Description The purpose of this challenge is to manually manipulate character arrays. This challenge...
Given java code is below, please use it! import java.util.Scanner; public class LA2a { /** * Number of digits in a valid value sequence */ public static final int SEQ_DIGITS = 10; /** * Error for an invalid sequence * (not correct number of characters * or not made only of digits) */ public static final String ERR_SEQ = "Invalid sequence"; /** * Error for...
Our lab today revolves around Character Strings (C-Strings) which are essentially character arrays. We’ll be writing two functions that will output the number of vowels and consonants in a user inputted string. We’ll be using functions from the cstring library, so be sure to include it! We’ll be calling those functions method_one and method_two. To start off, declare a character array (with no size) called vowels and initialize it with “aeiouyAEIOUY” in our main function. Declare a character array with...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...