Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You're to write a C++ program that allows the user to enter the name of an input file and the name of an output file.

You're to write a C++ program that allows the user to enter the name of an input file and the name of an output file. If the filenames are identical, you should display an error message and shut down the program, otherwise use the filenames to open an input file and an output file. If both files are opened successfully, you're ready to pass them as arguments to the RevFile function.

The RevFile function will read the input file, one line at a time, and copy the lines to the output file. However, each output line will be copied to the output file in reverse order! So if the line "abc" is read from the input file, you'll write "cba" to the output file. Once the end of the input file has been reached, RevFile will return the total number of lines written to the caller.

How on earth will you do this? It's helpful to take some time to think about a few things:

How can you read an entire single line of text from an input stream? Remember a function called .getline()? That function will allow you to fetch a null-terminated cstring from the input stream and copy it to a destination character array.

The .open() member function for file stream objects allows you to open a file, and the argument we've always used for that function has been a string literal. Well, now that we know a string literal is really just an unnamed cstring, and the the .getline() function allows you to get a cstring from the user at the keyboard, this means you can now get the names of files to open from the user.

How will you write the string to the output stream in reverse? You should realize that the string will be contained in an array of chars, and that the array is null-terminated. So, all you have to do is derive the index location of the null character, and walk backwards through the string, one character at a time until you reach the first character, which will be at index location zero. (Hint: It's not required, but the strlen function might help you with this task...).. Please make comments in order for me to know what each line of code does

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

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Briefly describe four guides to ethical decision-making

Answered: 1 week ago

Question

8. Measure the effectiveness of the succession planning process.

Answered: 1 week ago

Question

7. Determine what feedback is provided to employees.

Answered: 1 week ago