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 assistance on this problem in Pseudocode and in C++ Program Program 3: Give a...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by...
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...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2:...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT