Question: https://drive.google.com/open?id=0BxVUm6sFZ_-EM2ItTTJhMGlKeUk >>>> numbers.txt C++ Download and save this input file numbers.txt that contains many numbers. The first line contains a string. The rest of the

https://drive.google.com/open?id=0BxVUm6sFZ_-EM2ItTTJhMGlKeUk >>>>numbers.txt

C++

Download and save this input file numbers.txt that contains many numbers.

The first line contains a string. The rest of the file contains a bunch of integer numbers separated by one or more spaces. You should write the code to read the file data, then calculates and displays the average, the smallest, and the largest number. The code also displays the count of numbers that are larger than the average number and displays the count of numbers that are smaller than the average number.

Download the numbers.txt file and save it in the same folder as your CodeBlocks project.

Notes:

1- Do NOT hard-code any absolute file location with folder name for the input file inside your code like this

C:\John PC\My Documents\CIS22A\HW umbers.txt

because your code will fail on any other PC different than yours.

Put only the file name "numbers.txt" in the code that opens the file. This is the concept of "current working directory" (CWD) that I mentioned in class. When you are running Code Blocks with an existing project, the CWD is the project folder, and CodeBlocks will ony find the input file in this folder.

If you work on the Mac, you have to find out which folder you should place the file into because the default CWD folder may not be the same as the Code Blocks project folder.

2- Do not hard-code the count of numbers in your code. Assume that the file can contain any count of numbers after the first string. If your code is well written, it should work without modification when the file contains either 50 numbers or 5000000 numbers. This is the same concept for Microsoft Word that can process your document no matter how large your document is.

3- Use setw() to format the results.

4- Do not use array or any thing that was not presented in class lecture so gar because it is either not needed or bad practice (like goto statement).

5- The input file has to be first opened, processed, and closed to find the sum , then calculate the average. Then the file is opened again, processed, and closed again to count of numbers below and above the average.

If the file numbers.txt is not in the current Code Blocks project folder, display a meaningful error message and exit the program. Do not perform any calculation if input file is not found.

6- The first line in the file should be read with a simple file read statement using >> operator. Then use a "while" loop to read all numbers using >> operator, the same way that was shown in Chapter 5.

7- To get the lowest number, define a integer variable and intitialize it to the highest possible integer value INT_MAX as defined in the climits include. Then inside the loop that reads numbers, compare this number with newly read number and replace it as necessary.

To get the highest number, define a integer variable and intitialize it to the lowest possible integer value INT_MIN as defined in the climits include. Then inside the loop that reads numbers, compare this number with newly read number and replace it as necessary.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!