Question: Write a C++ program that Prompts the user for an input file name and opens the input file for reading. If the input file does

Write a C++ program that Prompts the user for an input file name and opens the input file for reading. If the input file does not exist then exit the program after displaying an appropriate message. Read each line of the file. For each line of the file, create a line of output where: The order of words in the line is reversed, i.e. the last word in the line is displayed first, and the first word of the line is displayed last The first and last characters of each word in the line are swapped. For example, if the original line is Hello World then the output would be: dorlW oellH Your program must implement and use the following functions with the function signatures as shown: void openFile(ifstream &); - This function accepts an input file stream variable passed by reference. The function prompts the user for a file name, and then opens the file for input. If the file does not exist then the function re-prompts the user. The function must not return until a valid file name has been entered, and the input file is open. This function must be used to open the input file in your program. string swap_ends(string); - This function accepts a C++ std::string object and returns the input string with the first and last characters swapped. For example, if the input is "line" then the return string would be "enil". This function must be used to swap the first and last characters of your input strings in preparation for output. string reverse_line(string); - This function accepts a C++ std::string object representing a line of input (multiple words), and returns the input with the words in reverse order. For example, if the input line is "Hello World" then the return value would be "World Hello". This function must be used to generate the "reversed order" lines for output. string reverse_chars(string); - This function accepts a C++ std::string object and returns a string with the original characters in reverse order. For example, if the input is "hello" then the return value would be "olleh".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!