Home /
Expert Answers /
Computer Science /
c-1-prompt-read-a-file-name-and-open-the-file-2-do-a-priming-read-and-make-a-while-loopto-if-pa935
(Solved): C++ 1. Prompt \& read a file name and open the file. 2. Do a priming read and make a while loopto If ...
C++
1. Prompt \& read a file name and open the file. 2. Do a priming read and make a while loopto If you do not know what 'priming read' is, then look it up in the text. a. Read in the numbers, b. Sum them up, and c. Count how many there are. words, every 10 numbers that you read in you print the average. See the example. 3. Finally... after the loop, calculate the average and print it. Use fixed and setprecision(2) for the average but not the count of numbers. Read in double numbers to average; Usually you use ints when counting. Your loop should look something like this: I/ read a number while ( your-ifstream-variable) \{ I/ sum number If count 1/ if (count \& 10 ) =0 I/ then cout "With xxx numbers, the average is YYYYY." I/ read a number 1 cout final average output
Example I/O Enter a file name: nums.dat With 10 numbers, the average is 32.23. With 20 numbers, the average is 36.14. with 30 numbers, the average is 44.66. with 40 numbers, the average is 39.34. With 50 numbers, the average is 40.22. There are 54 numbers in the file with an average of 43.25. Enter a file name: nums2. dat With 10 numbers, the average is 32.23. There are 19 numbers in the file with an average of 33.20. Enter a file name: nums 3 . dat There are 1 numbers in the file with an average of 3.20. Enter a file name: nums4.dat There are 4 numbers in the file with an average of 23.25.