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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void readF(int bry[], int &sz);
void OrigPrintF(int bry[]);
int AverageF(int cry[], int sum, int sz);
int Largest(int cry[], int sz, int &LgIndex);
ifstream inputFile;
int size;
int sum;
int ary[100];
int main()
{
int average;
int LgNum;
int SmNum;
cout << "This is an array workout program designed to manipulate an array.\n" << endl;
OrigPrintF(ary);
cout << "\n";
cout << endl;
average = AverageF(ary, sum, size);
LgNum = Largest(ary, size, LgIndex);
cout << "Original Array Average: " << average << "\n" << endl;
cout << "Largest Number in Array: " << LgNum << "\n" << endl;
system("PAUSE");
return 0;
}
///////////////////////////Funcion to read input into array//////////////////////////////
void readF(int bry[], int &sz)
{
int i = 0;
inputFile.open("E:\\array.txt");
if (inputFile.fail())
{
cout << "Cannot open file array.txt!" << endl;
return;
}
while (inputFile != 0)
{
inputFile >> bry[i];
i++;
}
sz = i;
return;
}
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////Funcion to print input from array//////////////////////////////
void OrigPrintF(int bry[])
{
int i = 0;
readF(ary, size);
cout << "Original array printed 10 numbers per line: " << endl;
while (bry[i] != 0)
{
if ((i % 10) == 0)
{
cout << endl;
}
cout << bry[i] << " ";
i++;
}
return;
}
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////Funcion to print average of array//////////////////////////////
int AverageF(int bry[], int sum, int sz)
{
int i = 0;
sum = 0;
while (i < sz)
{
sum = sum + bry[i];
i++;
}
sum = sum / sz;
//cout << "Average: " << sum << endl;
return sum;
}
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////FUNCTION THAT LOCATES THE LARGEST NUMBER IN ARRAY//////////////////////
int Largest(int cry[], int sz, int &LgIndex)
{
readF(ary, size);
int index = 0;
int BO = cry[0];
for (i = 0; i < sz; i++)
{
if (cry[i] > BO)
{
BO = cry[i];
index = i;
}
}
return BO;
}
//////////////////////////////////////////////////////////////////////////////////////////
|