Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 14.12 in C++ How to Program(9th Edition) by Deitel, Paul; Deitel, Harvey

ID: 3665982 • Letter: P

Question

Problem 14.12 in C++ How to Program(9th Edition) by Deitel, Paul; Deitel, Harvey BSN(0133379299)

Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table: Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in the above table to develop the seven-letter word 'NUMBERS.' Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. If a business can advertise a simple word for its customers to dial, then no doubt the business will receive a few more calls. Each seven-letter word corresponds to exactly one seven-digit telephone number. The restaurant wishing to increase its take-home business could surely do so with the number 825-3688 (i.e., TAKEOUT). Each seven-digit phone number corresponds to many separate seven-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. It's possible, however, that the owner of a barber shop would be pleased to know that the shop's telephone number, 424-7288, corresponds to 'HAIRCUT." A veterinarian with the phone number 738-2273 would be happy to know that the number corresponds to 'PETCARE.' Write a program that, given a seven-digit number, writes to a file every possible seven-letter word corresponding to that number. There are 2187 (3 to the seventh power) such words. Avoid phone numbers with the digits 0 and 1.

Explanation / Answer

#include #include #include const char *myarray[] = { "abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "prs", "aab", "bbc", "wxy" }; void performprocess(int num,char q[]); int main() { int i = 0; char number[8]; char q[7][4]= {0}; printf("enter 7 digit number > "); for (i = 0; i < 7; i++) cin>>number[i]; for (i = 0; i < 7; i++) { performprocess(number[i] - '0', q[i]); fprintf(stdout, "Word %d: %-3.3s ", i + 1, q[i]); } system("pause"); return 0; } void performprocess(int num,char p[]){ strcpy(p, myarray[num]); }