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
Give me username ideas for rblx.
alexandr1967 [171]

Answer: Larz7, Dracofli0, butterbro171,OVOclan1011, ect.

Explanation:

4 0
2 years ago
Read 2 more answers
Now you are ready to implement a spell checker by using or quadratic. Given a document, your program should output all of the co
Harlamova29_29 [7]

Answer:

Sorry po idont know po ehhh sorry

5 0
2 years ago
The following program is supposed to display a message indicating if the integer entered by the user is even or odd. What is wro
Lapatulllka [165]

Answer:

A. The function definition must appear before the function is called

Explanation:

Given

The above lines of code

Required

Determine the error in the program

In python, functions has be defined before they are called but in this case (of the given program), the function is called before it was defined and this will definitely result in an error;

<em>Hence, option A answers the question</em>

The correct sequence of the program is as follows:

<em>def evenOdd(n): </em>

<em>      if n % 2 == 0: </em>

<em>            return "even" </em>

<em>      return "odd" </em>

<em>num = int(input("Enter an integer: ")) </em>

<em>print("The integer is", evenOdd(num)) </em>

<em />

6 0
2 years ago
IN MICROSOFT EXCEL YOU CAN UES FOMULA TO DIVIDE OR MULTIPLY WHAT IS THE CORRECT FORMULA TO CALCULATE 4*6
nexus9112 [7]

You actually have the correct answer. An excel formula starts with = so your answer would be =4*6

8 0
3 years ago
How to upgrade brainly membership
rjkz [21]

Answer:

Go on account settings, go to subscription, and upgrade.

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Which data type uses more memory an integer or an unsigned integer?
    6·1 answer
  • Changeover means that ____. (select all that apply)
    7·2 answers
  • Match the items.
    15·1 answer
  • Purpose Your goal is to create a design for a software interface. You will experience the scope of the design process from brain
    7·1 answer
  • Write the function header (the first line of the function definition) to define a function named DisplayStats that accepts a str
    5·1 answer
  • How do you write the slope-intercept form?
    5·1 answer
  • How does light move? Shift? Bounce between different objects?
    9·1 answer
  • The recipient list cannot be edited.<br> Group of answer choices<br><br> True<br><br> False
    5·1 answer
  • I recorded a video on my windows PC, but when i tried to play it i got this message:
    6·2 answers
  • During the ___ phase of a software development project, members broadly define the features that the software should include
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!