Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Can you guys help me with my code? My parameters for the function arrayStats

ID: 3763231 • Letter: C

Question

C++ Can you guys help me with my code? My parameters for the function arrayStats is wrong and I don't know why.

#include

#include

using namespace std;

int COLS;

void arrayStats(int Matrix[][COLS],int rows)

{

int columnSum = 0, SIZE = 5;

  

for (int col = 0; col <= 1; col++)

{

for (int row = 0; row < 5; row++)

{

columnSum = columnSum + Matrix[row][col];

}

}

  

double TotalSum = 0, TotalAvg, colAvg;

int SmallestValue = 10000, LargestValue = 0;

  

colAvg = columnSum / 10;

cout << "Column 1 and 2: Sum = " << columnSum << " Average = " << colAvg << endl << endl;

  

for (int a = 3; a < SIZE; a++)

{

for (int b = 0; b < SIZE; b++)

{

if (Matrix[a][b] <= SmallestValue && SIZE - 1)

{

SmallestValue = Matrix[a][b];

}

}

}

  

for (int c = 3; c < SIZE; c++)

{

for (int d = 0; d < SIZE; d++)

{

if (Matrix[c][d] >= LargestValue && SIZE - 1)

{

LargestValue = Matrix[c][d];

}

}

}

  

cout << "Row 4 and 5: Min = " << SmallestValue << " Max = " << LargestValue << endl << endl;

  

for (int x = 0; x < SIZE; x++)

{

for (int y = 0; y < SIZE; y++)

{

TotalSum = TotalSum + Matrix[x][y];

}

}

TotalAvg = TotalSum / 25;

cout << "Array: Sum = " << TotalSum << " Average = " << TotalAvg << endl << endl;

}

int main()

{

int Cols = 5, Rows = 0, SIZE = 5, Matrix[Rows][Cols];

ofstream fout;

fout.open("Numbers.txt");

for(int i=1;i<=25;i++)

fout << i << endl;

fout.close();

  

  

string line;

ifstream File;

File.open("Numbers.txt");

  

if (!File)

cout << "Error: File could not be opened. " << endl;

  

  

while (Rows < SIZE)

{

for (Rows = 0; Rows < SIZE; Rows = Rows + 1)

for(Cols = 0; Cols < 5; Cols = Cols + 1)

File >> Matrix[Rows][Cols];

  

}

  

for (Rows = 0; Rows < 5; Rows = Rows + 1)

{

for (Cols = 0; Cols < 5; Cols = Cols + 1)

{

cout << Matrix[Rows][Cols] << " ";

}

cout << endl;

}

  

while(getline(File, line))

{

cout << line << endl;

}

  

File.close();

  

arrayStats(Matrix, COLS);

  

return 0;

}

Explanation / Answer

void arrayStats(int Matrix[][COLS],int rows)

you don't need to specift COLS, as when you invoke arrayStats function, a reference to already existing matrix is passed to function.

void arrayStats(int Matrix[][],int rows) <-- Correct