Question

I'm quite stuck with this C++ question, I would greatly appreciate the help! Many companies use...

I'm quite stuck with this C++ question, I would greatly appreciate the help!

Many companies use telephone number like 888- COM - CAST so the number is easier for their customer 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

W, X, Y, and Z = 9

Write an application that asks the user to enter a 10 – character telephone number in the format xxx-xxx-xxxx. The application should

display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For

example, if the user enters 888-COM-CAST the application should display 555-266-2278.

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

#include <iostream>

#include <string.h>

#include <algorithm>

using namespace std;

int main(){

//delaring variable to store input of user

string Num;

cout<<"Please enter string to convert number";

cin>>Num;

for(int i=0;i<=Num.length();i++){

int j=1;

string r = Num.substr(i,j);

if(r=="A" || r=="B" || r=="C" ){

Num.replace(i,j, "2");

}else if(r=="D" || r=="E" || r=="F"){

Num.replace(i,j, "3");

}else if(r=="G" || r=="H" || r=="I"){

Num.replace(i,j, "4");

}else if(r=="J" || r=="K" || r=="L"){

Num.replace(i,j, "5");

}else if(r=="M" || r=="N" || r=="O"){

Num.replace(i,j, "6");

}else if(r=="P" || r=="Q" || r=="R" || r=="S"){

Num.replace(i,j, "7");

}else if(r=="T" || r=="U" || r=="V"){

Num.replace(i,j, "8");

}else if(r=="W" || r=="X" || r=="Y" || r=="Z"){

Num.replace(i, j, "9");

}

else{

}

j=j+1;

}

cout<<"Phone Number:"<<Num;

}

main.cpp O saved gcc version 4.6.3 #include <iostream> Please enter string to convert number 888-COM-CAST Phone Number:888-266-2278 3 #include <string.h> 5 #include <algorithm> 7 using namespace std,; 18 11 12 13 14 15 16 17 18 19 28 21 9 int main)f //delaring variable to store input of user string Num; cout<<Please enter string to convert number; cin>>Num for(int i-e; ǐく-Num , length();i++){ int j 1; 23 string r Num.substr(i,j): 24 25 if (rA r--B I r--C ) 26 27 Num.replace(i,j, 2); 28 29 else if (r-- D I r--E r--F

Add a comment
Know the answer?
Add Answer to:
I'm quite stuck with this C++ question, I would greatly appreciate the help! Many 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
  • 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...

  • This is for a C# program. I would greatly appreciate any help! Thank you:) For this...

    This is for a C# program. I would greatly appreciate any help! Thank you:) For this assignment you're going to create a console application called A02PBallGenerator. This app is going to mimic a quick pick program in a lotto terminal. When the user runs your app you're going to select the numbers for them. Then you'll ask them if they'd like another set of numbers. Y for yes and N for No Use a do while loop so that if...

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