Write, CCompile and EExecute a C++ program that inputs a telephone number as a
string in the form (392) 630-1234. The program should use standard function strtok( )
to extract the area code (sequence of digits shown in parentheses) as a token, the first three
digits of the phone number as a token, and the last four digits of the phone number as a token. The seven
digits of the phone number should be concatenated into one string containing no blanks. Both the area code
and the phone number are then sent to the output.
The initial part of the program may look as follows (You are free to follow it or to make certain modifications):
Code:
#include <iostream >
using namespace std;
... ... < other files for inclusion > ... ...
#include <cstring >
int main( )
{
const int SIZE1 = 20;
... ... < other declarations, if needed > ... ...
char p[ SIZE1 ];
char * tokenPtr; // store temporary token
char * areaCode; // store area code (token 1)
char * phone; // store the phone number
cout << "Enter a phone number in the form (555) 555-5555: ";
cin.getline( p, SIZE1 );
... ... ... // remaining part of the program
}
Hypothetical dialogue may have the form given below:
Enter a phone number in the form (555) 555-5555: (392) 630-1234
Output:
Area code (token 1) is 392
Telephone number (concatenated tokens 2 and 3) is 6301234