Answered! Write a program that reads each line in a file, reverses its characters, and writes the resulting line to another file….

Write a program that reads each line in a file, reverses its characters, and writes the resulting line to another file. Suppose the user specifies input.txt and output.txt when prompted for the file names, and input.txt contains the lines Mary had a little lamb Its fleece was white as snow And everywhere that Mary went the lamb was sure to go.

After the program is finished, output.txt should contain bmal elttil a dah yraM wons sa etihw saw eceelf stI tnew yraM taht erehwyreve dnA .og ot erus saw bmal ehT

Expert Answer

 Following is the required program for above mentioned problem. It’s been compiled and run in Code::Blocks IDE and is a genuine piece of work.

The code BEGINS from here:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{

// Input file to read
ifstream inFile(“input.txt”);

// Output file to write
ofstream outFile(“output.txt”);

string sRead;

// Read each line and write it in reverse in output File
while(getline(inFile,sRead))
outFile << string(sRead.rbegin(), sRead.rend()) << ‘n’;

cout << “nProgram has executed successfully!”;
cout << endl;
return 0;
}

The code ENDS here!

Screenshots:

1. Input File: input.txt

2. Console Screen:

3. Output File: output.txt

Hope the code meets all your requirements…

Still stressed from student homework?
Get quality assistance from academic writers!