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

Write a program that reads a data file called RandNumLond.dat This file contains

ID: 3628469 • Letter: W

Question

Write a program that reads a data file called RandNumLond.dat This file contains no more than 1,000 integers, with one integer value each line. The value of each integer ranges from 0 to 5000. Your program should read these numbers into a one dimensional array and read until it reaches the end of the file. Using array, write the answers to the following questions to the screen.

*ow many numbers are in the dat file.
*What is the average value? (display the answers to two decimal places of accuracy)
*What is the largest (maximum) value in the array?
*What is the smallest (minimum) value in the array?

Your program may read the data file in the main function and fill the array. The function listed below are called from main.

double findAve(int { }, int); - pass the array and total in the array, return the average value
double findMax(int { }, int); - pass array and total in the array, return the maximum value
double findMin(int { }, int); - pass array and total in the array, return the minimum value

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
using namespace std;
double findAvg(int[],int);
double findMax(int[],int);
double FindMin(int[],int);
int main()
{int a[1000],n=0;
ifstream input;
input.open("RandNumLond.dat");           //open file
   if(input.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        return 1;
        }  
input>>a[n];
while(input&&n<1000)
   {n++;
    input>>a[n];
   }
cout<<"The file has "<<n<<" numbers ";
cout<<"The average value is: "<<findAvg(a,n)<<endl;
cout<<"The largest number is: "<<(int)findMax(a,n)<<endl;
cout<<"The smallest number is: "<<(int)FindMin(a,n)<<endl;
input.close();
system("pause");
return 0;
}
double findAvg(int a[],int n)
{int i,sum=0;
for(i=0;i<n;i++)
    sum+=a[i];
return sum/(double)n;
}
double findMax(int a[],int n)
{int i,big=a[0];
for(i=1;i<n;i++)
     if(a[i]>big)
          big=a[i];
return (double)big;
       }
double FindMin(int a[],int n)
{int i,small=a[0];
for(i=1;i<n;i++)
     if(a[i]<small)
          small=a[i];
return (double)small;
}