Answer:
<em>The program goes as follows </em>
<em>Comments are used to explain difficult lines</em>
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
int main()
{
//Declare String to accept file name
string nm;
//Prompt user for file name
cout<<"Enter File Name: ";
getline(cin,nm);
//Create File
ofstream Myfile(nm.c_str());
//Prompt user for 4 names of movies
string movie;
for(int i = 1;i<5;i++)
{
cout<<"Please enter a movie title #"<<i<<": ";
cin>>movie;
//Write to file, the names of each movies
Myfile<<movie<<endl;
}
Myfile.close(); // Close file
//Create an Array for four elements
string myArr[4];
//Prepare to read from file to array
ifstream file(nm.c_str());
//Open File
if(file.is_open())
{
for(int i =0;i<4;i++)
{
//Read each line of the file to array (line by line)
file>>myArr[i];
}
}
file.close(); // Close file
//Create a reverseOrder.txt file
nm = "reverseOrder.txt";
//Prepare to read into file
ofstream Myfile2(nm.c_str());
for(int j = 3;j>=0;j--)
{
//Read each line of the file to reverseOrder.txt (line by line)
Myfile2<<myArr[j]<<endl;
}
Myfile2.close(); //Close File
return 0;
}
See attached for .cpp program file