Question

In: Computer Science

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 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 telephone numbers until the user enters EXIT for a telephone number.

For Example:

Enter a telephone number using letterss (EXIT to quit): GET LOAN
The corresponding telephone number is:
438-5626
Enter a telephone number using letterss (EXIT to quit): CaLl Home
The corresponding telephone number is:
225-5466

Solutions

Expert Solution

#include <stdio.h>
#include <string.h>
char getNumber(char aC) {
       char c = ' ';
       switch (aC) {
       case 'A':
       case 'B':
       case 'C':
           c = '2';
           break;
       case 'D':
       case 'E':
       case 'F':
           c = '3';
           break;
       case 'G':
       case 'H':
       case 'I':
           c = '4';
           break;
       case 'J':
       case 'K':
       case 'L':
           c = '5';
           break;
       case 'M':
       case 'N':
       case 'O':
           c = '6';
           break;
       case 'P':
       case 'Q':
       case 'R':
       case 'S':
           c = '7';
           break;
       case 'T':
       case 'U':
       case 'V':

           c = '8';
           break;
       case 'W':
       case 'X':
       case 'Y':
       case 'Z':

           c = '9';
           break;

       }
       return c;
   }
int main()
{
char str[100];
char *uppr;
while(1){
printf("\nEnter a telephone number using letterss (EXIT to quit):");
gets(str);
if(strcmp(str,"EXIT")==0)
break;
int i=0;
for(i=0;i<8;i++){
if(i==3){
printf("-");
  
}
if(str[i]==' ')
continue;

if(str[i]>='a' && str[i]<='z'){
str[i]=str[i]-32;
}
printf("%c",getNumber(str[i]));
}
  
}
printf("\nBye....");
return 0;
}


Related Solutions

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...
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...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
In C program #include<stdio.h> Write a program that prompts the user to input the elapsed time...
In C program #include<stdio.h> Write a program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. Example (Numbers with underscore indicate an input): Enter the elapsed time in seconds: 9630 The elapsed time in seconds = 9630 The equivalent time in hours:minutes:seconds = 02:40:30 HINT: Pay attention to the printf format descriptors.
*Answer in C program* #include <stdio.h> int main() {      FILE *fp1;      char c;     ...
*Answer in C program* #include <stdio.h> int main() {      FILE *fp1;      char c;      fp1= fopen ("C:\\myfiles\\newfile.txt", "r");      while(1)      {         c = fgetc(fp1);         if(c==EOF)             break;         else             printf("%c", c);      }      fclose(fp1);      return 0; } In the program above which statement is functioning for opening a file Write the syntax for opening a file What mode that being used in the program. Give the example from the program Referring to...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I have random array [4,2,7,1,9,8,0]. Sort the array's index but cannot change the position of item in the array, if you copy the array to a new array, you also cannot change the item's position in array. The index now is[0,1,2,3,4,5,6] The output should be[6,3,1,0,2,5,4]
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...
(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...
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            ...
construct c program flow chart #include <stdio.h> #include <math.h> #include <string.h> #define num 6 #define b...
construct c program flow chart #include <stdio.h> #include <math.h> #include <string.h> #define num 6 #define b 6 #define t 6 double bmical(double w, double h){ double o; double bmi; o = pow(h,2); bmi = w/o; return bmi; } double maxheartrate(int num1, int age){ double mhr; mhr = num1 - age; return mhr; } double heartratereserve(double mhr, double rhr){ double hrr; hrr = mhr - rhr; return hrr; } double minrange(int hrr, int rhr){ double mirt; mirt = (hrr * 0.7)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT