Question

In: Computer Science

C++: (I need this program to output in a certain format I will post the "needed...

C++: (I need this program to output in a certain format I will post the "needed results" below)

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 letter. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than seven letters, than process only the first seven letters. Also output the - (hyphen after the third digit. Allow the user to use both upper case and lowercase letters as well as spaces between words. moreover, your program should process as many telephone numbers as the user wants.

Desired Outputs:

Enter Y/y to convert a telephone number from letters to digits. Enter any other letter to terminate the program.

y

Enter a telephone number using 7 or more letters for prefix and number, onnly the first 7 letters are used and spaces are not counted.

-->: To Be or not

The corresponding telephone number is:

862-3676

To process another telephone number, enter Y/y Enter any other letter to terminate the program.

y

Enter a telephone number using 7 or more letters for Prefix and number, only the first 7 letters are used and spaces are not counted

--> YRU Here?

The corresponding telephone number is:

978-4373

To process another telephone number, enter Y/y Enter any other letter to terminate the program.

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<iostream>

#include<cctype>

#include<string>

using namespace std;

int main(){

    string telephone_str, choice;

    string telephone_num = "";

    cout<<"Enter Y/y to convert a telephone number from letters to digits. Enter any other letter to terminate the program."<<endl;

    cin>>choice;

    while(choice=="Y" || choice=="y"){

        telephone_num = "";

        cout<<"Enter a telephone number using 7 or more letters for prefix and number, only the first 7 letters are used and spaces are not counted."<<endl;

        cout<<"-->: ";

        cin.clear();

        cin.ignore(100, '\n');

        getline(cin, telephone_str);

        int i=0, k=0;

        while(i<telephone_str.size() && k<7){

            switch(toupper(telephone_str[i])){

                case 'A':

                case 'B':

                case 'C':

                    telephone_num += '2';

                    break;

                case 'D':

                case 'E':

                case 'F':

                    telephone_num += '3';

                    break;

                case 'G':

                case 'H':

                case 'I':

                    telephone_num += '4';

                    break;

                case 'J':

                case 'K':

                case 'L':

                    telephone_num += '5';

                    break;

                case 'M':

                case 'N':

                case 'O':

                    telephone_num += '6';

                    break;

                case 'P':

                case 'Q':

                case 'R':

                case 'S':

                    telephone_num += '7';

                    break;

                case 'T':

                case 'U':

                case 'V':

                    telephone_num += '8';

                    break;

                case 'W':

                case 'X':

                case 'Y':

                case 'Z':

                    telephone_num += '9';

                    break;

            }

            if(telephone_str[i]!=' '){

                if(k==2)

                    telephone_num+='-';

                k++;

            }

            i++;

        }

        cout<<"The corresponding telephone number is: "<<telephone_num<<endl;

        cout<<"To process another telephone number, enter Y/y Enter any other letter to terminate the program."<<endl;

        cin>>choice;

    }

    return 0;

}


Related Solutions

c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
I have this matlab program, and need to turn it into a C++ program. Can anyone...
I have this matlab program, and need to turn it into a C++ program. Can anyone help me with this? % Prompt the user for the values x and y x = input ('Enter the x coefficient: '); y = input ('Enter the y coefficient: '); % Calculate the function f(x,y) based upon % the signs of x and y. if x >= 0    if y >= 0        fun = x + y;    else        fun = x + y^2;    end...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
I need C++ programming with output. I have tried other programming and it does not work....
I need C++ programming with output. I have tried other programming and it does not work. So please give me the one that actually works. Assignment 1 Design your own linked list class that works as a template class. It should provide member functions for appending, inserting and deleting nodes. The destructor should destroy the list. The class should also provide a member function that will display the contents of the list to the screen. The class should also provide...
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
I need to write a C++ program that appends "not" into the string without using the...
I need to write a C++ program that appends "not" into the string without using the append method or any standard libraries. It should return the string if there isn't an "is" in it. Examples: is is = is not is not This is me = This is not me What is yellow? = What is not yellow? The sky is pink = The sky is not pink isis = isis What happened to you? = What happened to you?
I need to write a program in C with the following specification * ​​​​​​​Line one of...
I need to write a program in C with the following specification * ​​​​​​​Line one of the standard input will have the total number of people which must not be greater than 10 * Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number * Each name must be a maximum of 14 characters * Put the first names into an array called...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not against it being included in the answer* I must read off of an excel file (comma separated) to input five different things for a book, all comma separated, there are 360 books in the file. The book title, author, ISBN number, number of pages, and finally the year it was published. Now some of the ISBN or Pg numbers may be missing and will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT