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 call RandNumLond.dat. this file contains

ID: 3628381 • Letter: W

Question

Write a program that reads a data file call RandNumLond.dat. this file contains no more than 1,000 integers, with one integer value on each line. The value of each interger 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 the array, write the answers to the following questions to the screen. How many numbers are in the data file? What is the average value? (Display the answer to two decimal place of accuracy). What is the largest maximum number value n the array? What is the smallest? Your program may read the file in the main function and fill ty.
Function prototypes
Double findAvg (int { } , int) ; passes the array and total in the array, returns the average
Double findMax (int { }, int); passes the array and total in array, returns the maximum. Double FindMin (int { }, int); passes the array and total, retuurn minimum

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;
}

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