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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started