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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
void computeSums(int fishArray[][4], int rowSum[], int colSum[]);
void computeAvgs(int rowSum[], int colSum[], double rowAvg[], double colAvgs[]);
int main()
{
ifstream FileIn;
ofstream FileOut;
FileIn.open("D:\\Datafile3.txt");
FileOut.open("D:\\FISHDATA2015.TXT");
int row, column;
int fishArray[6][4];
for (row = 0; row < 6; row++)
for (column = 0; column < 4; column++)
FileIn >> fishArray[row][column];
cout << setw(21) << "Cropi" << setw(8) << "Bass" << setw(10) << "Catfish" << setw(8) << "Trout"
<< setw(8) << "Sums" << setw(10) << "Averages" << endl << endl;
for (row = 0; row < 6; row++)
{
cout << "Keystone" << row + 1 << " ";
for (column = 0; column < 4; column++)
{
cout << setw(8) << fishArray[row][column] << computeSums << computeAvgs;
}
cout << endl << endl;
}
}
void computeSums(int fishArray[][4], int rowSum, int colSum[])
{
int row = 0, column = 0;
for (row = 0; row < 6; row++)
{
cout << setw(2) << fishArray[row] << setw(10) << rowSum[row] << endl;
}
}
void computeAvgs(int rowSum[], int colSum[], double rowAvg[], double colAvgs[])
{
int row = 0, column = 0;
for (row = 0; row < 6; row++)
{
for (column = 0; column < 4; column++)
{
cout << setw(10) << rowSum[row] / 4.0 << endl;
}
}
}
|