Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Code in C++ In order to read from/write to a file, we need to take some precise steps. Missing any of these steps, will result

Code in C++

In order to read from/write to a file, we need to take some precise steps. Missing any of these steps, will result in failure to correctly read from/write to a file. Following are the steps that you need to go through to successfully perform the file I/O.

  1. Step (1): Include the required directives
  2. Step (2): Create the input/output streams
  3. Step (3): Connect the input stream to an input file/the output stream to an output file
  4. Step (4): Use the input stream to read from the input file/the output stream to write the output file
  5. Step (5): Close the input and output files by disconnecting the corresponding streams

Write a program that reads a file containing some integer values (we do not know how many values).

For the even numbers, it writes the numbers, the number to the power of two, and the sum up to that point and also writes the average of all the numbers to a text file displays the average of these numbers.

data.dat:

1 2 3 4 5 6 7 8

x x^2 Current Sum === === ========== 2 4 2 4 16 6 6 36 12 8 64 20

The average of these 4 numbers is: 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Accounting questions