Question: need help with this assignment ASAP! please help! 5.9 Lab 34: Numbers from a File The textbook source code chapter 5 folder contains a file

need help with this assignment ASAP! please help!

need help with this assignment ASAP! please help! 5.9 Lab 34: Numbers

from a File The textbook source code chapter 5 folder contains a

5.9 Lab 34: Numbers from a File The textbook source code chapter 5 folder contains a file named Sales.txt which contains a list of numbers. Write a program that will do the following with the file named sales.txt: open the file and if the file does not exist, it gives an error message . If the file exists, it reads the numbers from the file in a loop and calculates the following: o the count of numbers in the file, o the sum of all the numbers in the file (a running total), o the average of all the numbers in the file (perform integer division), o When all numbers have been read in, it then displays the count, the sum, and the average as shown below It closes the file when all data has been processed. Hint: Pr5-23.cpp is loaded into your template Study it and make the necessary changes When sales.txt contains the data shown in Figure 1. your program should produce the output as shown in Figure 2. Please note that the Sales.txt file attached to this assignment has different values in it than what appears in Figure 1, therefore, your program will produce different output when you run it in Develop mode. Figure 1: (Sales.txt - different values than the assignment) 1000 2000 3000 4000 5000 Figure 2: (sample output - based on Figure 1 values, not the assignment Sales.txt values) The number of elements: 5 The sum of elements: 15000 The average of elements: 3000 17/ Your Name 2 // CS 1336.exe 3 // Lab 34 4 5 // This program is Pr5-23.cpp from your textbook. It tests for file open errors. 6 // If the file is successfully opened, it reads in values and processes them until the EOF is reached. 7 #include 8 #include 9 using namespace std; 18 11 int main() 12 13 ifstream inputFile; 14 int number: 15 16 I Open the file. inputFile.open("BadListofNumbers.txt"); 18 19 11 If the file successfully opened, process it. 2e if (inputFile) 21 22 Read the numbers from the file and 22 I display them. 24 while (inputFile >> number) { cout

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!