Many websites ask for phone numbers. The problem is that there are so many diffe
ID: 3854195 • Letter: M
Question
Many websites ask for phone numbers. The problem is that there are so many different ways to represent a phone number. Examples include 817-555-1234, 817 555 1234 (c), and (817) 555-1234 x23. Write a Raptor program which inputs a string containing a phone number in any format and outputs it in the standard format. For this assignment, the standard format is (817) 555-1234. Your Raptor program should: Input a string including the number Copy only the digits from the input string into another string Issue an error message if the input string does not contain exactly 10 digits Output the phone number in standard formatExplanation / Answer
#include<iostream>
#include<cctype>
#include<string>
#include <sstream>
#include <iomanip>
using namespace std;
double i;
long num,d,n;
int g,h,r,c;
string sn;
stringstream strs;
int main()
{
do{
cout << "Enter a string with numbers in it: ";
getline(cin, sn);
while (1)
{
for ( i=0; i < sn.length(); i++)
if (!isdigit(sn[i]))
continue;
else
strs << sn[i];
strs >> num ;
//cout << num ;
break;
}
cout<<num<<endl;
while(n!=0)
{
r=n%10;
c=c+1;
n=n/10;
}
}while(c!=10);
d=num;
g=num%10000;
num=num/10000;
h=num%1000;
num=num/1000;
cout<<"("<<num<<")"<<"-"<<h<<"-"<<g;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.