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
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
phonebook.txt
543,2021000 543,2021006 543,2021025 543,2021061 543,2021063 543,2021066 543,2021080 543,2021116 543,2021117 543,2021132 543,2021158 543,2021159 543,2021164 543,2021167 543,2021175 543,2021214 543,2021240 543,2021271 543,2021273 543,2021329 543,2021354 543,2021357 543,2021360 543,2021361 543,2021397 618,5041000 618,5041006 618,5041025 618,5041061 618,5041063 618,5041066 618,5041079 618,5041080 618,5041116 618,5041117 618,5041132 618,5041158 618,5041159 618,5041164 618,5041167 618,5041175 618,5041214 618,5041240 618,5041271 618,5041273 618,5041329 618,5041360 618,5041361 618,5041397 814,8981000 814,8981006 814,8981025 814,8981061 814,8981063 814,8981066 814,8981079 814,8981080 814,8981116 814,8981117 814,8981132 814,8981158 814,8981159 814,8981164 814,8981167 814,8981175 814,8981214 814,8981240 814,8981271 814,8981273 814,8981329 814,8981354 814,8981357 814,8981360 814,8981361 814,8981397
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
