1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
katrin [286]
3 years ago
12

p25: File Write and Read1) User enters a file name (such as "myMovies.txt").2) User enters the titles of 4 of their favorite mov

eis (use a loop!).3) Program Writes the 4 titles to a file, one per line, then closes the file (use a loop!).4) Program Reads the 4 titles from "myMovies.txt" stores them in a list and shows the list5) The program writes the titles in reverse order into a file "reverseOrder.txt"Sample Run:Please enter a file name: myMovies.txtPlease enter a movie title #1: movie1Please enter a movie title #2: movie2Please enter a movie title #3: movie3Please enter a movie title #4: movie4Writing the 4 movie titles to file 'myMovies.txt'Reading the 4 movie titles from file into a list: [movie1, movie2, movie3, movie4]Writing the 4 movie titles in revers to 'reverseOrder.txt'Note: Do not use reverse() , reversed()Content of myMovies.txt:movie1movie2movie3movie4Content of reverseOrder.txtmovie4movie3movie2movie1
Computers and Technology
1 answer:
SCORPION-xisa [38]3 years ago
6 0

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

Download cpp
You might be interested in
Marty uses a customized database to sort parts and track inventory. The customized database is an example of _____.
Alexeev081 [22]

cataloging is a term for that

5 0
3 years ago
A type of malicious code that appears to be a safe program but that actually has a hidden purpose is called a _____.
masha68 [24]

This is a trojan horse type of virus.

5 0
3 years ago
Read 2 more answers
State one advantage of organising data into columns and rows
Bezzdna [24]
It's neat organized and ready to find when needed
6 0
3 years ago
Porque sophia es un robot mujer?
gregori [183]
Sophia es un robot humanoide (ginoide) desarrollado por la compañía, con sede en Hong Kong, Hanson Robotics. Ha sido diseñada para aprender, adaptarse al comportamiento humano y trabajar con estos satisfactoriamente.
7 0
2 years ago
Given the following code: public class Test { public static void main(String[] args) { Map map = new HashMap(); map.put("123", "
Phoenix [80]

Answer:

There are no statements in the question, so I explained the whole code.

Explanation:

A map consists of key - value pairs. The put method allows you to insert values in the map. The first parameter in the put method is the key, and the second one is the value. Also, the keys must be unique.

For example, map.put("123", "John Smith");   -> key = 123, value = John Smith

Even though the key 123 is set to John Smith at the beginning, it will have the updated value Steve Yao at the end. That is because the keys are unique.

Note that the key 222 also has Steve Yao for the value, that is totally acceptable.

5 0
3 years ago
Other questions:
  • Please use Python 3 to solve the following problem. Please also show all outputs and share code.The variable sentence stores a s
    6·1 answer
  • The CSS relative positioning property called ____ moves the element relative to its original position but preserves the space re
    9·1 answer
  • What does rwd stand for?
    8·2 answers
  • Your friend sees an error message during Windows startup about a corrupted bootmgr file. He has another computer with a matching
    12·1 answer
  • A light or optical microscope most commonly used is called a(n) _____. bright-field microscope dark-field microscope electron mi
    8·2 answers
  • You are running out of storage space on one of your servers. you need to purchase an external hard drive, as there are no drive
    8·2 answers
  • How many pounds must a sand bag weigh to test if a safety net can absorb the proper amount of force? A. 150 lbs. B. 200 lbs. C.
    6·1 answer
  • Why is dark supereffective against ghost?
    5·2 answers
  • SmartArt is a Microsoft Office tool for creating what?
    11·2 answers
  • ____ uses a computer to design and test new products and modify existing ones. Computer-aided manufacturing Just-in-time design
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!