Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements: Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file. Save the output of the program in a file. Write a function called getNumber which reads a number from the input file, outputs the number to the output file and the monitor and sends the input number to the function main. Make sure, both input and out file are being opened in the main program. Write a function called classifyNumber which counts number of even, odd, and zero (occurrences of zero) available in the input file. Have the program find the sum and average of the numbers and print only 10 numbers per line. Write a function called printResult so that it outputs (in output file and monitor) even number of counts, odd number of counts, number of zeros, sum of the numbers and average of the numbers. Make sure output file is being opened in the function main.   Create an input file using the following data: 43 67 82 0 35 28 -64 7 -87 0 0 0 0 12 23 45 7 -2 -8 -3 -9 4 0 1 0 -7 23 -24 0 0 12 62 100 101 -203 -340 500 0 23 0 54 0 76

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 5SA
icon
Related questions
Topic Video
Question
100%

Practice problem we were given in C++ to review for test. Thanks

Write a program that reads data from a data file, the value of which is provided at the end of the problem. Your program is to incorporate the following requirements:

  • Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.
  • Save the output of the program in a file.
  • Write a function called getNumber which reads a number from the input file, outputs the number to the output file and the monitor and sends the input number to the function main. Make sure, both input and out file are being opened in the main program.
  • Write a function called classifyNumber which counts number of even, odd, and zero (occurrences of zero) available in the input file.
  • Have the program find the sum and average of the numbers and print only 10 numbers per line.
  • Write a function called printResult so that it outputs (in output file and monitor) even number of counts, odd number of counts, number of zeros, sum of the numbers and average of the numbers. Make sure output file is being opened in the function main.

 

Create an input file using the following data:

43 67 82 0 35 28 -64 7 -87 0 0 0 0 12 23 45 7 -2 -8 -3 -9 4 0

1 0 -7 23 -24 0 0 12 62 100 101 -203 -340 500 0 23 0 54 0 76

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Instruction Format
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning