Question

In: Computer Science

C++ Summary To make telephone numbers easier to remember, some companies use letters to show their...

C++

Summary

To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN.

In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters.

Instructions

Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits.

If the user enters more than seven letters, then process only the first seven letters.

Also output the - (hyphen) after the third digit.

Allow the user to use both uppercase and lowercase letters as well as spaces between words.

Moreover, your program should process as many telephone numbers as the user wants.

Use the dialpad below for reference:

The program should accept input and produce output similar to the example program execution below.

Enter Y/y to convert a telephone number from
letters to digits.
Enter any other letter to terminate the program.
Y
Enter a telephone number using letters: Hello world

The corresponding telephone number is:
435-5696
To process another telephone number, enter Y/y
Enter any other letter to terminate the program.
z

Solutions

Expert Solution

#include <iostream>

#include <iomanip>

#include <string>

#include <cctype>

using namespace std;

int main()

{

int done = 0;

int flag;

int count = 1;

char word, letter;

int Phone_Num;

while (done != 1)

{

flag = 0;

count = 1;

cout << "Enter a telephone number using letters:";

while (flag == 0)

{

cin >> word;

// converting word to uppercase letters

word = toupper(word);

// swtich case to get the number for equalant char

switch (word)

{

case 'A':

case 'B':

case 'C':

Phone_Num = 2;

break;

case 'D':

case 'E':

case 'F':

Phone_Num = 3;

break;

case 'G':

case 'H':

case 'I':

Phone_Num = 4;

break;

case 'J':

case 'K':

case 'L':

Phone_Num = 5;

break;

case 'M':

case 'N':

case 'O':

Phone_Num = 6;

break;

case 'P':

case 'Q':

case 'R':

case 'S':

Phone_Num = 7;

break;

case 'T':

case 'U':

case 'V':

Phone_Num = 8;

break;

case 'W':

case 'X':

case 'Y':

case 'Z':

Phone_Num = 9;

break;

}

// if count reaches 4 than print -

if(count == 4)

cout << "-" << Phone_Num;

else

cout << Phone_Num;

if(count >= 7)

{

cout << endl;

while (cin.get() != '\n' );

flag = 1;

}

count++;

}

cout << "Do you want to make another number? enter Y or N " << endl;

cin >> letter;

if (letter == 'n' || letter == 'N')

done = 1;

}

return 0;

}


Related Solutions

To make telephone numbers easier to remember, some companies use letters to show their telephone number....
To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Instructions Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone...
In C program #include<stdio.h> To make telephone numbers easier to remember, some companies use letters to...
In C program #include<stdio.h> To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME,which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters/spaces and...
In PYTHON On a standard telephone, alphabetic letters are mapped to numbers in the following fashion:...
In PYTHON On a standard telephone, alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and O = 6 P, Q, and R = 7 T, U, and V = 8 W, X, Y, and Z = 9 Write a fruitful function that takes any string of alphanumeric characters and returns a string...
Alphabetic Telephone Number Translator           Many companies use telephone numbers like 555-GET-FOOD so the number is...
Alphabetic Telephone Number Translator           Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2             D, E, and F = 3             G, H, and I = 4             J, K, and L = 5             M, N, and O = 6             P, Q, R, and S = 7            ...
•• P11.1 Phone numbers and PIN codes can be easier to remember when you find words...
•• P11.1 Phone numbers and PIN codes can be easier to remember when you find words that spell out the number on a standard phone keypad. For example, instead of remembering the combination 2633, you can just think of CODE. Write a recursive function that, given a number, yields all possible spellings (which may or may not be real words). •• P11.2 Continue Exercise P11.1, checking the words against the /usr/share/dict/words file on your computer, or the words.txt file in...
3 Food and Beverage The food industry has many acronyms that make it easier to remember...
3 Food and Beverage The food industry has many acronyms that make it easier to remember food safety terms and actions to control foodborne illness. Managers must know what safety precautions are necessary. Food, Acidity, Temperature, Time, Oxygen, and Moisture is often referred to with the acronym FATTOM. Read the scenario and respond to the checklist item. Scenario: You are catering a wedding buffet in August outside on a venue’s terrace for a wedding reception for 200 people that begins...
Show that any polynomial over C (the complex numbers) is the characteristic polynomial of some matrix...
Show that any polynomial over C (the complex numbers) is the characteristic polynomial of some matrix with complex entries. Please use detail and note any theorems utilized.
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
Please show all steps and write neatly. Make sure the proving is with letters and not...
Please show all steps and write neatly. Make sure the proving is with letters and not with numbers. Please!!!! Thank you Let A, B, C be 3 x 3 matrices. Show (AB)C= A(BC)
The major advantage of using structs is to make the C++ code simpler, easier to read,...
The major advantage of using structs is to make the C++ code simpler, easier to read, and easier to work with. After completing this assignment, students will be able to: • use structs to create and/or introduce new custom data types • implement structs to group fixed numbers of pieces of data of different types • implement structs within structs • chaining using the dot operators to access nested fields • copy an entire structure • create an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT