Answer:
#include <iostream>
#include <climits>
#include<fstream>
using namespace std;
int main ()
{
fstream filein;
ofstream fileout;
string inputfilename, outputfilename;
// ASk user to enter filenames of input and output file
cout<<"Enter file input name: ";
cin>>inputfilename;
cout<<"Enter file output name: ";
cin>>outputfilename;
// Open both file
filein.open(inputfilename);
fileout.open(outputfilename);
// Check if file exists [Output file will automatically be created if not exists]
if(!filein)
{
cout<<"File cannot be opened"<<endl;
return 0;
}
int min = INT_MAX;
int max = INT_MIN; //(Can't use 0 or any other value in case input file has negative numbers)
int count = 0; // To keep track of number of integers read from file
double average = 0;
int number;
// Read number from file
while(filein>>number)
{
// If min > number, set min = number
if (min>number)
{
min = number;
}
// If max < number. set max = number
if(max<number)
{
max = number;
}
// add number to average
average = average+number;
// add 1 to count
count+=1;
// If count reaches 10, break the loop
if(count==10)
{
break;
}
}
// Calculate average
average = average/count;
// Write result in output file
fileout<<"Max: "<<max<<"\nMin: "<<min<<"\nAverage: "<<average;
// Close both files
filein.close();
fileout.close();
return 0;
}