Use C++ Please provide screenshot of code. please include every detail and a code that can be copied and pasted. Thank you! In this program you will be reading numbers from a file. You will validate the numbers and calculate the average of all of the valid numbers. Your program will read in a file with numbers. The numbers will be of type double. The numbers should be in the range from 0 to 105 (inclusive). You need to count all of the numbers between 0 and 105. You also need to calculate the average of these numbers. The average will be written out with four digits to the right of the decimal point. If a number is not valid (that is, it is less than 0 or greater than 105) you need to count it (as a count of invalid values) and you need to write out the number to a file called "invalid-values.txt". Values written to file invalid-values.txt should be in fixed format with five digits to the right of the decimal point. As you did in lab lesson 7 part 1 you need to read in the input file name using cin. The prompt for the input file name is: Enter input file name The output from your program will be written to cout. The output must contain the file being processed, the total number of values read in from the file, the number of invalid values read in, the number of valid values read in. The last thing you need to output is either the average of the valid values or an error message. The average must have four digits of precision to the right of the decimal point and must be in fixed format. If there is not valid average you should output the message: An average cannot be calculated In what case would you display this message? If the input file cannot be opened, you will need to output a message. Assume the input file name is badinput.txt and it cannot be opened. You will display the following error message to cout File "badinput.txt" could not be opened Here is an example of a working program: Assume the file name read in from cin is: input.txt and that input.txt contains: -12 0 98.5 100 105.5 93.5 88 75 -3 111 89 -12 Your program would output the following: Enter input file name Reading from file "numbers.txt" Total values: 12 Invalid values: 5 Valid values: 7 Average of valid values: 77.7143 The contents written out to file invalid-values.txt are: -12.00000 105.50000 -3.00000 111.00000 -12.00000 You are reading from an input file and you are writing to an output file. Make sure you close both files after you are finished using them. You must do this in your program, you cannot just let the operating system close the files for you.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Use C++

Please provide screenshot of code.

please include every detail and a code that can be copied and pasted.

Thank you!

In this program you will be reading numbers from a file. You will validate the numbers and calculate the average of all of the valid numbers.

Your program will read in a file with numbers. The numbers will be of type double.

The numbers should be in the range from 0 to 105 (inclusive). You need to count all of the numbers between 0 and 105. You also need to calculate the average of these numbers. The average will be written out with four digits to the right of the decimal point.

If a number is not valid (that is, it is less than 0 or greater than 105) you need to count it (as a count of invalid values) and you need to write out the number to a file called "invalid-values.txt". Values written to file invalid-values.txt should be in fixed format with five digits to the right of the decimal point.

As you did in lab lesson 7 part 1 you need to read in the input file name using cin. The prompt for the input file name is:

Enter input file name

The output from your program will be written to cout. The output must contain the file being processed, the total number of values read in from the file, the number of invalid values read in, the number of valid values read in.

The last thing you need to output is either the average of the valid values or an error message. The average must have four digits of precision to the right of the decimal point and must be in fixed format. If there is not valid average you should output the message:

An average cannot be calculated

In what case would you display this message?

If the input file cannot be opened, you will need to output a message. Assume the input file name is badinput.txt and it cannot be opened. You will display the following error message to cout

File "badinput.txt" could not be opened

Here is an example of a working program:

Assume the file name read in from cin is:

input.txt

and that input.txt contains:

-12

0

98.5

100

105.5

93.5

88 75

-3

111

89

-12

Your program would output the following:

Enter input file name Reading from file "numbers.txt" Total values: 12 Invalid values: 5 Valid values: 7 Average of valid values: 77.7143

The contents written out to file invalid-values.txt are:

-12.00000

105.50000

-3.00000

111.00000

-12.00000

You are reading from an input file and you are writing to an output file. Make sure you close both files after you are finished using them. You must do this in your program, you cannot just let the operating system close the files for you.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 7 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education