Question

In: Computer Science

Write a program that reads the letter codes of a telephone number pad and converts them...

  1. Write a program that reads the letter codes of a telephone number pad and converts them into their corresponding number patterns.
  2. a.        One acceptable form of output:

Sample input:              Sample Output:

800-MATTRESS 800-628-8737 (leave off the last “S”)

800-mattress                800-628-8737 (leave off the last “S”)

  1. Another acceptable form of output:

Sample input:              Sample Output:

            8   8

0   0

  0 0

   M 6

A 2

T                                8

T                                8

R                                7

E                                 3

S                                 7

  1. The letters ‘A’ to ‘Z’ and ‘a’ to ‘z’ should print the corresponding telephone digit.
  2. This program should use two levels of loops.
    1. One loop should prompt the user to ask them if they wish to convert a telephone letter pattern. The user should be prompted when the program first begins execution and after each completed execution.
    2. (1)             If they do wish to convert a telephone letter pattern, the program should execute again.

(2)             If they do not wish to convert a telephone letter pattern, the program should

terminate

(3) Valid values that the user can enter as to whether they wish to execute the

program are: ‘Y’ or ‘y’ or “N’ or ‘n’ .

(a)      All other responses should error out and user the should be requested to

           enter a valid response.            

    1. The other loop should convert a 10 character letter pattern into the corresponding number pattern.
  1.             The user should be prompted to enter the 10 letter sequence.
  2.             Only the first 10 characters should be able to be entered and converted.
    1. The valid patterns for letter to number conversion of the telephone are:

1

2: ABC

3: DEF

4: GHI

5: JKL

6: MNO

7: PQRS

8: TUV

9: WXYZ

*

0

#

A counter should keep track of how many telephone button conversions have been processed on and printed on the report.

A solid line of separators such as the **** or #### should be placed between each telephone button conversion done.

Place a good descriptive heading at the top of the report below the required first several output lines indicated at the top of this document.

At least three separate conversions should be processed.

D.        Save the program with the name: Lab4tele.cpp

E.        Test Data:

           

Test Case Number

Phrase

Output

1

800-Compute

?

2

808-Science

?

3

888-Program

?

F.         For this program, hand in:

  1. A copy of the source code for the program.
  2. A copy of the screen print for the output for the program run.

PLEASE USE ANY LOOP(FOR, WHILE, DO). DO NOT USE STRINGS OR ARRAYS.  

Solutions

Expert Solution

thanks for the question, here is the complete code in C++.

Have used two while loops and have not used string or arrays : )

thanks, let me know for any questions or help. if you are satisfied please do rate.

===================================================================

# include <iostream>

using namespace std;

// takes in a character and decodes the character and returns it

char getDigit(char letter){

                if('0'<=letter && letter<='9') return letter;

                switch(letter){

                                case 'a':case 'b' : case 'c' : case 'A':case 'B' : case 'C' : return '2';

                                case 'd':case 'e' : case 'f' : case 'D':case 'E' : case 'F' : return '3';

                                case 'g':case 'h' : case 'i' : case 'G':case 'H' : case 'I' : return '4';

                                case 'j':case 'k' : case 'l' : case 'J':case 'K' : case 'L' : return '5';

                                case 'm':case 'n' : case 'o' : case 'M':case 'N' : case 'O' : return '6';

                                case 'p':case 'q' : case 'r' : case 's':case 'P' : case 'Q' : case 'R': case 'S': return '7';

                                case 't':case 'u' : case 'v' : case 'T':case 'U' : case 'V' : return '8';

                                case 'w':case 'x' : case 'y' : case 'z':case 'W' : case 'X' : case 'Y': case 'Z': return '9';

                }

               

}

int main(){

               

                char repeat;

               

                do{

                                cout<<"Enter the 10 letter sequence you like to convert : ";

                               

                                int digitsPrinted = 0;

                                char character;

                               

                                while (digitsPrinted<10){

                                                cin>>character;

                                                if(('0'<=character && character <='9') ||

                                                                ('a'<=character && character <='z') ||

                                                                ('A'<= character && character <='Z') ){

                                                                                cout<<getDigit(character)            ;

                                                                                digitsPrinted++;

                                                                                if(digitsPrinted==3 || digitsPrinted==6) cout<<"-";

                                                                }

                                }

                                cin.ignore(1024,'\n'); // flush all extra characters

                                cout<<endl<<"============"<<endl;

                               

                                do{

                                                cout<<"Do you want to repeat again (y/Y/n/N): ";

                                                cin>> repeat;

                                                if((!(repeat=='Y' || repeat=='y' || repeat =='n' || repeat == 'N')))cout<<endl<<"Sorry: Invalid character entered\n\n";

                                               

                                }while(!(repeat=='Y' || repeat=='y' || repeat =='n' || repeat == 'N'));

                }while(repeat=='y' || repeat =='Y');

}

===================================================================


Related Solutions

Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them...
Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them into Turtle commands, and then executes them. The codes are in a Python list, passed as an argument to your function. turtleRunner(t, x) t is a Turtle x is a list of Turtle commands Code List (f, d)    Move forward by d pixels u Lift pen up d Put pen down (l, d) Turn left by d degrees (r, d) Turn right by...
PYTHON: Turtle Command Interpreter You will write a program that reads a sequence of codes, converts...
PYTHON: Turtle Command Interpreter You will write a program that reads a sequence of codes, converts them into Turtle commands, and then executes them. The codes are in a Python list, passed as an argument to your function. turtleRunner(t, x) t is a Turtle x is a list of Turtle commands Code List (f, d)    Move forward by d pixels u Lift pen up d Put pen down (l, d) Turn left by d degrees (r, d) Turn right...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a program that uses a dictionary to assign “codes” to each letter of the alphabet....
Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example:      codes = {'A':'%', 'a':'9', 'B':'@', 'b':'#', etc....} Using this example, the letter “A” would be assigned the symbol %, the letter “a” would be assigned the number 9, the letter “B” would be assigned the symbol “@” and so forth. The program should open a specified text file, read its contents, and then use the dictionary to write an encrypted version of...
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the...
(Tokenizing Telephone Numbers) Write a program that inputs a telephone number as a string in the form (555) 555-5555. The program should use function strtok to extract the area code as a token, the first three digits of the telephone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. The program should convert the area-code string to int and convert...
Write a program that translates a letter grade into a number grade. Letter grades are A,...
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts Enter a Letter grade: B- The numeric value is 2.7 Your code with comments A screenshot...
Write a program that accepts a number of minutes and converts it both to hours and...
Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. (I currently have what is below) import java.util.Scanner; public class MinutesConversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numOfMinutes = sc.nextInt(); double hour = numOfMinutes/60.00; double days = (hour/24); System.out.println(numOfMinutes + " minutes is " + hour + " hours or " + days + " days.");...
Write a program that accepts a number of minutes and converts it to days and hours....
Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values. Save the file as  MinuteConversionWithExceptionHandling.java
Write a program that converts the user's number into the desired unit of measurement. The user...
Write a program that converts the user's number into the desired unit of measurement. The user will pick the desired unit from a menu shown below. Ask the follow-up question (the number to convert) and do the math ONLY if the user picks a valid choice from the menu. You can see the conversions / multipliers needed for this program in the output section below. Menu/Prompt: Enter the number that corresponds to your desired unit conversion from the choices below:...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT