Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer by using C++ Write a program that reads in a series of numbers, as strings, from a file and converts them to valid

Please answer by using C++

Write a program that reads in a series of numbers, as strings, from a file and converts them to valid telephone numbers.

The numbers are contained in file is called numbers.txt.

The numbers must read into the file using a loop, and stored as an array of strings. Note that you may assume that the size of the array is known ahead of time to be 10.

As it reads in each number, it should convert the number to a valid telephone number in the format XXX.XXX.XXXX by calling a function named formatPhone.

Here is the information about this function:

The function is named formatPhone

It take in a string variable by reference

It alters the string to be a properly formatted phone number, in the format XXX.XXX.XXXX

This function must use the substring function to format the numbers

It returns nothing.

The program must also contain a second function which writes out the contents of the array in a file named phones.txt

Here is the information about the second function:

The function is named printArray

It takes in two parameters - one is an array of strings, and the second is an int for the size of the array

It creates a new output file stream variable and opens up a file called phones.txt

It also checks for failure if the file cannot open

It uses a for loop to print out the contents of the array in the file.

It then closes the file.

It returns nothing.

Copy and paste the starter code below into a new file called phones.cpp

/* * Name * Section info */ #include #include #include using namespace std; void formatPhone(string& number); //converts a string to a formatted phone number in the format XXX.XXX.XXXX

void printArray(string nums[], int size);

//prints out an array to a file named phones.txt

int main() { //write the program logic here

string number;

} //write your functions here

Copy and paste the below data into a file called numbers.txt:

5556667777 3334445555 1118884944 3332225677 1234445555 8889990000 1116664344 2224563333 1112229999 4568899399

Below is the output that your program should give inside of the phones.txt file

555.666.7777 333.444.5555 111.888.4944 333.222.5677 123.444.5555 888.999.0000 111.666.4344 222.456.3333 111.222.9999 456.889.9399

Once you have the correct output inside of the phones.txt file, your program is complete.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions

Question

3. How has e-commerce transformed marketing?

Answered: 1 week ago