I\'m quite stuck with this C++ question, I would greatly appreciate the help! Ma
ID: 3755108 • Letter: I
Question
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.
Explanation / Answer
#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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.