Ask Question

C++: The program Telephone Digits outputs only telephone digits that correspond to uppercase letters. Rewrite the program so that it processes both uppercase and lowercase letters and outputs the corresponding telephone digit. If the input is something other than an uppercase or lowercase letter, the program must output an appropriate error message.

+1
Answers (1)
  1. 17 May, 12:49
    0
    Following are the program written in the C+ + Programming Language:

    #include / /header file

    using namespace std; / /using namespace

    int main () / /main function

    {

    char letters;

    cout << "To stop the program enter 0" << endl;

    cout << "Enter letter: ";

    cin >> letters;

    //set while loop

    while (letters! = '0' && letters > = 'A' && letters < = 'z') {

    cout << "The letter you entered: " << letters << endl;

    cout << "corresponding telephone digits is: ";

    if (letters > 'Z') { / /if statement

    letters = (int) letters-32; / / letters covertion

    }

    switch (letters) { / /switch statement

    case'A':

    case'B':

    case'C':

    cout << "2" << "/n""/n"; / /print message

    break; / /break the statement

    case'D':

    case'E':

    case'F':

    cout << "3" << "/n""/n"; / /print message

    break; / /break the statement

    case'G':

    case'H':

    case'I':

    cout << "4" << "/n""/n"; / /print message

    break; / /break the statement

    case'J':

    case'K':

    case'L':

    cout << "5" <<"/n""/n"; / /print message

    break; / /break the statement

    case'M':

    case'N':

    case'O':

    cout << "6" <<"/n""/n"; / /print message

    break; / /break the statement

    case'P':

    case'Q':

    case'R':

    case'S':

    cout << "7" << "/n""/n"; / /print message

    break; / /break the statement

    case'T':

    case'U':

    case'V':

    cout << "8" << "/n""/n"; / /print message

    break; / /break the statement

    case'W':

    case'X':

    case'Y':

    case'Z':

    cout << "9" << "/n""/n"; / /print message

    break; / /break the statement

    default:

    break; / /break the statement

    }

    //print and return letters

    cout << "Enter another letter to find out the number: ";

    cin >> letters;

    }

    return 0;

    }

    Output:

    To stop the program enter 0

    Enter letter: a

    The letter you entered: a

    corresponding telephone digits is: 2

    Enter another letter to find out the number: S

    The letter you entered: S

    corresponding telephone digits is: 7

    Enter another letter to find out the number: 0

    Explanation:

    Here, we define header file "" and namespace "std" then, we define main () function.

    Then, inside the main function we set character data type variable "letters" and then print message and get input from the user in the variable "letters". Then, we set the while loop and pass the condition then, we set the if statement and print two message. Then, we set the switch statement inside the while loop and pass the letter variable in it's parameter then, we set the following cases of the switch statement. Finally, we print the message and print the value of the variable "letters" then, return 0 and close the main () function.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “C++: The program Telephone Digits outputs only telephone digits that correspond to uppercase letters. Rewrite the program so that it ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers