Question: #include #include #include using namespace std; void initialize (int a [4][5]); void print (int my_arr [4][5]); void zero_all (int my_arr [4][5]); void zero_row (int a
#include
#include
#include
using namespace std;
void initialize (int a [4][5]);
void print (int my_arr [4][5]);
void zero_all (int my_arr [4][5]);
void zero_row (int a [4][5], int row);
int main(int argc, char *argv[])
{
int rect [4][5];
// call initialize to initialize rect here
cout << "The initial array is: ";
// call print to print rect here
// call zero_row to zero all values in rect in row 1
cout << " The array with zeroed row 1 is: ";
// call print to print rect here
// call zero_row to zero all values in rect in row 3
cout << " The array with zeroed row 3 is: ";
// call print to print rect here
// call zero_all to zero all values in rect
cout << " The array with all zeros is: ";
// call print to print rect here
cout << " ";
return 0;
}
// initialize sets all values in the array to
// counting numbers
void initialize (int a [4][5])
{
int count, row, col;
count = 1;
for (row = 0; row < 4; row++)
for (col = 0; col < 5; col++)
{
a [row][col] = count;
count++;
}
}
// prints the elements of the array in 2 dimensional form
void print (int my_arr [4][5])
{
int r, c;
for (r = 0; r < 4; r++)
for (c = 0; c < 5; c++)
cout << setw (4) << my_arr [r][c];
}
// sets all values in the 2 D array to zero
void zero_all (int my_arr [4][5])
{
}
// sets all values of the given row in the 2 D array
// to zero
void zero_row (int a [4][5], int row)
{
}
Write the function definition for zero_all. It sets all the values in its array parameter to zero. Write loops to do this.
Write the function definition for zero_row. It sets the values in its array parameter in the given row to zero. Write a loop to do this.
Make function calls as directed by the comments in main.
Run your program. The print function does not properly space the array when printed. Fix the program so that the array is printed properly in 2 dimensions.
Submit your completed Lab3.cpp C++ source file on Blackboard.
1. Explain clearly why it makes sense to put the linefeed in that particular spot in the print function where you placed it.
please take Screenshot of the output
2. Switch the order of the two loops in the initialize function (col loop first and then row loop) and run your program. Explain what changed in the output and why.
3. Just before the final print in main, add the following assignment statement:
rect [1][6] = 20;
Run your program. Explain what happened.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
