Starting out with Programming Logic and Design: CH12, Programming Exercise 6 Alp
ID: 3916701 • Letter: S
Question
Starting out with Programming Logic and Design: CH12, Programming Exercise 6
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
T, U, and V = 8
W, X, Y, and Z = 9
Design a program that asks the user to enter a 10-character telephone number in
the format XXX-XXX-XXXX. The program should display the telephone number
with any alphabetic characters that appeared in the original translated to their
numeric equivalent. For example, if the user enters 555-GET-FOOD the program
should display 555-438-3663.
Answer must be given in pseudocode.
Explanation / Answer
function translate
{
print "enter telephone number in xxx-xxx-xxxx format"
read input as string
loop i from 0 to input.length
{
if input[i] is A or input[i] is B or input[i] is C then
print 2
else if input[i] is D or input[i] is E or input[i] is F then
print 3
else if input[i] is G or input[i] is H or input[i] is I then
print 4
else if input[i] is J or input[i] is K or input[i] is L then
print 5
else if input[i] is M or input[i] is N or input[i] is O then
print 6
else if input[i] is P or input[i] is Q or input[i] is R or input[i] is S then
print 7
else if input[i] is T or input[i] is U or input[i] is V then
print 8
else if input[i] is W or input[i] is X or input[i] is Y or input[i] is Z then
print 9
else print input[i]
}
}
//any query, post as comment
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.