// This program lets the user enter a filename.
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int getLowest(constint[], int);
int getHighest(constint[], int);
int main()
{
ifstream inputFile;
string filename;
int number;
constint ARRAY_SIZE = 12; // Array size
int numbers[ARRAY_SIZE]; // Array with 100 elements
int count = 0;
int lowestNumber, highestNumber , sumNumber=0;
// Get the filename from the user.
cout << "Please enter the name of the file to read numbers for Number Analysis Program:\n";
cin >> filename;
// Open the file.
inputFile.open(filename);
// If the file successfully opened, process it.
if (inputFile)
{
// Read the numbers from the file and
// display them.
while (count < ARRAY_SIZE && inputFile >> numbers[count])
count++;
// Close the file.
inputFile.close();
// Display the numbers read.
cout << "The numbers are: ";
for (int index = 0; index < count; index++)
cout << numbers[index] << " ";
cout << endl;
}
else
{
// Display an error message.
cout << "Error opening the file.\n";
}
for (int i = 0; 1 < ARRAY_SIZE; i++)
{
sumNumber += numbers[i];
}
cout << "The sum of the numbers are: " << sumNumber << endl;
// Get the lowest test score.
highestNumber = getHighest(numbers, ARRAY_SIZE);
lowestNumber = getLowest(numbers, ARRAY_SIZE);
system("pause");
return 0;
}
int getLowest(constint array[], int size)
{
int lowest; // To hold the lowest value
// Get the first array's first element.
lowest = array[0];
// Step through the rest of the array. When a
// value less than lowest is found, assign it
// to lowest.
for (int count = 1; count < size; count++)
{
if (array[count] < lowest)
lowest = array[count];
}
cout << "The lowest nuber is " << lowest << endl;
// Return the lowest value.
return lowest;
}
int getHighest(constint array[], int size)
{
int highest; // To hold the lowest value
// Get the first array's first element.
highest = array[0];
// Step through the rest of the array. When a
// value less than lowest is found, assign it
// to lowest.
for (int count = 1; count < size; count++)
{
if (array[count] > highest)
highest = array[count];
}
cout << "The highest nuber is " << highest << endl;
// Return the lowest value.
return highest;
}