Question

Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use...

Programming Concepts CS 225 for C++

To make telephone numbers easier to remember, some companies use digits and letters (or only letters) to show their telephone number. In some cases, to make a telephone number meaningful, companies might use more than seven digits and letters. Here are some examples:

Phone Number in Display

Note

Actual Phone Number

GET LOAN

-

438-5626

CALL HOME

More than seven digits/letters used for ease of remembrance.

225-5466

111 GOLD

-

111-4653

Glass4u

-

452-7748

Write a program that prompts the user to enter a telephone number expressed in letters (or digits and letters) and outputs the corresponding telephone number in digits. If the user enters more than seven characters, then process only the first seven valid digits. Also output a - (hyphen) after the third digit. Allow the user to use digits, both uppercase and lowercase letters, and spaces between words.

If a number contains invalid letters such as a number GOT $$99, your program should report and terminate the processing of that phone number (do not terminate the whole program) and ask for another number.

Your program should process as many telephone numbers as the user wants. You may use any valid approach to allow multiple sessions until user chooses to stop, such as CTRL+Z, enter y/n, enter q and so on. Whatever approach you use, provide proper prompt message(s) to users so they know how to use your program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/****************************phone.cpp*********************************/

#include<iostream>
#include<string>
#include <algorithm>
using namespace std;

int main(){
  
   //string array for text number and telephone number
   string phoneNumberDisplay[4] = {"getloan","callhom","111gold","glass4u"};
   string telephoneNumber[4] = {"4385626","2255466","1114653","4527748"};
   string textNumber;
   char option='?';
   do{
  
   cout<<"Enter a telephone number in text format: ";
   getline( cin, textNumber );//read all string with space
   textNumber.erase(remove(textNumber.begin(),textNumber.end(), ' '), textNumber.end());//remove space
   textNumber = textNumber.substr(0,7);//save only 7 letters
   transform(textNumber.begin(), textNumber.end(), textNumber.begin(), ::tolower);//change to lower case
   int flag = 0;
   //check for special character
   for(int i = 0; i<textNumber.length(); i++) {
  
   char ch = textNumber[i];
   if(ch>=97&&ch<=122||ch>=48&&ch<=57){
      
       flag = 1;
       }
   }
   //if no special character
   if(flag==1){
      
       int found = 0;
       for(int i = 0;i<4;i++){
           //if number found
           if(phoneNumberDisplay[i].compare(textNumber)==0){
              
               cout<<"Telephone number is: "<<telephoneNumber[i].substr(0,3)<<"-"<<telephoneNumber[i].substr(3,7)<<endl;
               found = 1;
           }
       }
      
       if(found==0){
          
           cout<<"Number not found!";
       }
   }
   else{
      
       cout<<"Number is not valid!";
   }  
   cout<<"Do you want any other number!(y/n): ";
   cin>>option;
   cin.ignore();
   }
   while(option!='n');
  
}

/*****************************output****************************************/

Enter a telephone number in text format: call HoME
Telephone number is: 225-5466
Do you want any other number!(y/n): y
Enter a telephone number in text format: get Loan'
Telephone number is: 438-5626
Do you want any other number!(y/n): y
Enter a telephone number in text format: 111Gold
Telephone number is: 111-4653
Do you want any other number!(y/n): y
Enter a telephone number in text format: glass4U
Telephone number is: 452-7748
Do you want any other number!(y/n): y
Enter a telephone number in text format: GOT $$99
Number not found!Do you want any other number!(y/n): n

--------------------------------

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to...

    4B : C PROGRAMMING 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...

  • 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 must see more than seven letters. For example, 255-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone expressed in letters and outputs the corresponding telephone number in...

  • Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone...

    Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone numbers easier to remember, some companies use letters to show their telephone number, but mapping the letters to the numbers on a standard telephone keypad: 1 2 ABC 3 DE 4G 5 11 6 MNO 7 PONS 8 Tu 9.xyz # For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone...

  • read all pls Assessment 1: Individual Assignment Weightage Submission Deadline Word Limit 30% TBA NA Assignment...

    read all pls Assessment 1: Individual Assignment Weightage Submission Deadline Word Limit 30% TBA NA Assignment Topic and Requirements You are supposed to write Java program for the following questions. For every question, do provide at least THREE (3) different test cases. Question 1 Please use netbeans! joptionpane needed! Question 3 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...

  • The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = ""...

    The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = "" # ADD YOUR CODE HERE return result def loadEvents(filename): events = {} # ADD YOUR CODE HERE return events def timeline(events): # ADD YOUR CODE HERE return # DO NOT modify or remove the code below! We will use it for testing. if __name__ == "__main__": # Problem 1: Decoding Telephone Numbers ph = input("Enter the text to translate: ") print("The corresponding phone number...

  • I don't know how to terminate the code in the second time that whether or not...

    I don't know how to terminate the code in the second time that whether or not the users want to continue to get a new number. PLEASE HELP. 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...

  • Letter to Number Converter: Create a program that reads a phone number as letters from a...

    Letter to Number Converter: Create a program that reads a phone number as letters from a variable and converts it to numbers e.g. GET-LOAN = 438-5626 When the company uses more than 7 letters, it should convert it to 7 digits e.g. CALL-HOME = 225-5466 The resulting converted number should include the dash to separate the three digits from the four digits Hint: Use the String object charAt method to read the variable that is storing the phone number as...

  • Help with programming in Raptor: Many companies use telephone numbers like 555-GET-FOOD so the number is...

    Help with programming in Raptor: 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...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Write a simple telephone directory program in C++ that looks up phone numbers in a file...

    Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT