Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The student cd contains a file named random.txt. This file contains a long list

ID: 3620159 • Letter: T

Question

The student cd contains a file named random.txt. This file contains a long list of random numbers. Copy the file to your hard drive and then write a program that opens the file, reads all the numbers from the file, and calculates the following.
A) The number of numbers in the file
B) The sum of all the numbers in the file( a running total)
c) The average of all the numbers in the file.

The program should display the number of numbers found in the file, the sum of the numbers, and the average of the numbers.

Explanation / Answer

please rate - thanks #include <iostream>
#include <fstream>
using namespace std;
   int main()
   {
    int i=0,num, sum=0;
    double average;
   ifstream input;
   input.open("random.txt");           //open file
   if(input.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        return 1;
        }
    input>>num;
   while(input)
       {i++;
       sum+=num;
       input>>num;
       }
    average=sum/(double)i;
    cout<<"The number of numbers in the file is: "<<i<<endl;
       cout<<"The sum of all the numbers in the file is: "<<sum<<endl;
       cout<<"The average of all the numbers in the file: "<<average<<endl;
       input.close();
      system("pause");
     return 0;
     }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote