Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ /* Introduction to files This program writes data to a file, then uses the same file to read data from it. - Generates n

C++

image text in transcribed

/* Introduction to files This program writes data to a file, then uses the same file to read data from it.

- Generates n random numbers within a given range, displays them to the screen, and writes them to a file. - Reads the numbers from the file, displays them to the screen, and calculates their average. - Displays the average of the random numbers. Finish the program following the specifications given as comments in the program. NAME: */ #include #include

// constants for the range of the random numbers const int MIN_R = -25; const int MAX_R = 25;

using namespace std;

int main() { ofstream outputFile; int rNum; int n; // Enter the number of random numbers to be written to a file cout > n; while ( n 20) // Input validation loop { cout > n; } // Open an output file. outputFile.open("Numbers.txt"); // Write n random numbers to the file for (int i = 0; i > rNum) { cout (sum) / n

return 0; }

6.11 LAB: Files (input and output) This program writes data to a file, then uses the same file to read data from it. Generates n random numbers within a given range, displays them to the screen, and writes them to a file. Reads the numbers from the file, displays them to the screen, and calculates their average. Displays the average of the random numbers. Finish the program following the specifications given as comments in the program. Note: The call for srand() has been omitted on purpose, to make sure that your output matches zyBook's output. Because there is no call for srand(), each time you run the program, it will generate the same random numbers. If you run this program on your own computer or use the online compiler, you are more likely going to get different numbers than the zyBook's numbers, because of the way random numbers are generated. For instance, when input is 8, the zy Book's solution generates the following random numbers: - 15 24 -16 9 7 12 12 23 When I run the program on my computer I got: 6 0 -20 -23 -3 -17 -1 1 When I run the program using the online C++ compiler I got: -6 9 -16 -18 -20 -18 -15 -13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

Students also viewed these Databases questions

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago