Write a program to read from the text file phonebook.txt and then do the followi
ID: 671888 • Letter: W
Question
Write a program to read from the text file phonebook.txt and then do the following:
(1) Ask for inputting an area code from keyboard, and print on screen how many phone numbers in the file have this area code.
(2) Format the phone numbers from (1) by inserting a comma "," before the last four digits (for example, 814,8981329 is changed to 814,898,1329) and output all the formatted phone numbers to a new text file: formattedphonebook.txt .
A sample run on screen and output file:
Enter Area Code to Extract: 814
Area Code 814 has 26 numbers.
All Phone Numbers = 75
you may use the substr method to take a substring of a string. For example,
string a("hello");
cout << a.substr(0, 3); // the first three letters "hel" will be printed out
Explanation / Answer
Program:
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.