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

#include <iostream> #include <iomanip> using namespace std; void Fill2DArray(int

ID: 3641525 • Letter: #

Question

#include <iostream>
#include <iomanip>
using namespace std;
void Fill2DArray(int [][15], int, int);
void Print2DArray(int[][15], int, int);
void LinearSearch (int[][15], int, double);

int main()
{
//declare an array for whole numbers that may contain 20 rows and 15 columns
int rows, columns, arr1[20][15], no_rows=0, no_columns=0;

cout<<"Please enter the dimensions of the 2D array."<<endl;
cout<<"Please enter the number of rows you want to use"<<endl;
cin>>rows;

while(rows <= 0 || rows > 20)
{
cout<<"The number of rows must be greater than 0 and less than or equal to 20"<<endl;
cout<<"Please enter the number of rows you want to use"<<endl;
cin>>rows;
}

cout<<"Please enter the number of columns you want to use"<<endl;
cin>>columns;

while(columns <= 0 || columns > 15)
{
cout<<"The number of rows must be greater than 0 and less than or equal to 15"<<endl;
cout<<"Please enter the number of rows you want to use"<<endl;
cin>>columns;
}

Fill2DArray(arr1, rows, columns);
Print2DArray(arr1, rows, columns);
LinearSearch(arr1, no_rows, no_columns);

return 0;
}

void Print2DArray(int arr1[][15], int rows, int columns)
{
int i = 0, j;
while (i < rows)
{
j = 0;
while (j < columns)
{
cout<<setw(5)<<arr1[i][j];
j++;
}
cout<<endl;
i++;
}
}

// Function is to fill array with numbers by the user.
void Fill2DArray(int arr1[][15], int no_rows, int no_columns)
{
for (int j = 0; j < no_rows; j++)
{ for (int k = 0; k < no_columns; k++)
{ cout<<"Ouput array: "<<endl;
cin>> arr1[j][k]; //interactive
}
}
}

// Function is to find the maximum number in the array.
int LinearSearch (int arr1[][15], int no_rows=0, int no_columns=0)
{
int max = arr1[0][0];
for (int j = 0; j < no_rows; j++)
{ for (int k = 0; k < no_columns; k++)
{
if (arr1[j][k] > max)
max = arr1[j][k];
}
}
return max;
}


It compiles, but when I go to run it, it says there are build errors. Can anyone help?


Explanation / Answer

In the function prototype of Linear Search at the start of your program, 1. The last argument (no_columns) is of type double - should have been int 2. Return type is void, should have been int - since the actual function definition has return type int The function prototype and definition should match - correct that, and your program will run :)