Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need in C++ thank you! /* Introduction to files This program writes data to a file, then uses the same file to read data

image text in transcribed

I need in C++ thank you!

/* 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 zy Book'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 zyBook's solution generates the following random numbers: -15 24 -16 9 7 12 12 23 When I run the program on my computer got: 60 -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 293630.1722736

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

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions