On ancient rotary telephones each letter of the alphabet (except Q and Z) was pa
ID: 3929809 • Letter: O
Question
On ancient rotary telephones each letter of the alphabet (except Q and Z) was paired with one of the dial-able numbers 2 through 9 according to the following table: The number 0 was used to contact the operator, and the number 1 was used to begin a long-distance call, so they were not paired with any letters. The * and # symbols were also reserved for special uses and were thus not paired with any letters. Using the letter-number pairing from the table, people and businesses were able to make their phone numbers easier to remember. For example, to call Wells Fargo bank, you can dial 1-800-T0-WELLS, or a local animal shelter might haw the number (FUN) DOG-N-CAT. Your job here is to write a Matlab function called how2call.m which takes a string wacky representing a phone number (and which may contain only upper-case letters, numbers, spaces, parentheses, and hyphens) and does the following: strips off the leading 1 (if one is present in wacky) changes the upper-case letters to numbers according to the table above removes all spaces, hyphens, and parentheses returns the phone number boring in the format (XXX) XXX-XXXX (where there is a space between the area code in parentheses and the beginning of the first 3 digit grouping). The specifications for the function and some sample function calls are shown below. input parameter wacky a string representing a phone number with letters, etc. output parameter boring a string representing a specially formatted phone number without letters .sample function calls hou2call('1-800-T0-WELLS') produces the siring '(800) 869-3557' how2call(' (FUN) DOG-N-CAT') produces the string ' (386) 364-6228' how2call('1 (404) CASH NOW') produces the string ' (404) 227-4669Explanation / Answer
function [boring] = how2call(wacky)
l=size(wacky,2);
disp(l);
res(1:10)='0';
i=1;
for j=1:l
if wacky(j)=='A'|| wacky(j)=='B'|| wacky(j)=='C'
res(i)='2';
i=i+1;
end
if wacky(j)=='D'|| wacky(j)=='E'|| wacky(j)=='F'
res(i)='3';
i=i+1;
end
if wacky(j)=='G'|| wacky(j)=='H'|| wacky(j)=='I'
res(i)='4';
i=i+1;
end
if wacky(j)=='J'|| wacky(j)=='K'|| wacky(j)=='L'
res(i)='5';
i=i+1;
end
if wacky(j)=='M'|| wacky(j)=='N'|| wacky(j)=='O'
res(i)='6';
i=i+1;
end
if wacky(j)=='P'|| wacky(j)=='S'|| wacky(j)=='R'
res(i)='7';
i=i+1;
end
if wacky(j)=='V'|| wacky(j)=='T'|| wacky(j)=='U'
res(i)='8';
i=i+1;
end
if wacky(j)=='X'|| wacky(j)=='W'|| wacky(j)=='Y'
res(i)='9';
i=i+1;
end
if wacky(j)=='0' || wacky(j)=='2' || wacky(j)=='3' ||wacky(j)=='4' || wacky(j)=='5' ||wacky(j)=='6' || wacky(j)=='7' ||wacky(j)=='8' || wacky(j)=='9'
res(i)=wacky(j);
i=i+1;
end
if wacky(j)=='-' || wacky(j)=='1' || wacky(j)==' ' || wacky(j)=='Q' || wacky(j)=='Z'
end
end
disp(res);
temp1=res(1:3);
temp2=res(4:6);
temp3=res(7:10);
boring=['(' temp1 ') ' temp2 '-' temp3];
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.