1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
void GetData(ifstream&, int [], int&);
void FindAverage (int [], int, int, int);
void FindSmallest (int [], int, int, int);
void PrintArray (int [], int, int, int, ofstream&);
int index[100];
int i;
int sum;
int smallestNum;
int minIndex;
int average;
ifstream inData;
ofstream outData;
void GetData (ifstream& inData, int index[ ], int& i)
{
i = 0;
inData >> index[i];
while (inData && i < 13)
{
i++;
inData >> index[i];
}
}
void FindSmallest (int index[], int minIndex, int i, int smallestNum)
{
minIndex = 0;
for (i = 1; i < 13; i++)
if (index[minIndex] > index[i])
minIndex = i;
smallestNum = index[minIndex] ;
}
void FindAverage (int index[], int sum, int i, int average)
{
sum = 0;
for (i = 0; i < 13; i++)
sum = sum + index[i] ;
average = sum / 13;
}
void PrintArray (int index[], int sum, int i, int average, ofstream& outData)
{
outData << cout << "The array contains these numbers ";
for (i = 0; i < 13; i++)
{
outData << cout << index[i] << " ";
cout<< endl;
}
outData << cout << '\n';
outData << cout << "The smallest array is " << minIndex << '\n';
outData << cout << "The average size is " << average;
}
int main()
{
inData.open("C:\\Users\\CaseySmith\\Documents\\Visual Studio 2010\\Projects\\Lab9 - B\\data1.txt");
outData.open("C:\\Users\\CaseySmith\\Documents\\Visual Studio 2010\\Projects\\Lab9 - B\\data1_output.txt");
GetData (inData, index, i);
FindAverage (index, sum, i, average);
FindSmallest (index, minIndex, i, smallestNum);
PrintArray (index, sum, i, average, outData);
inData.close();
outData.close();
return 0;
}
|