/*
CIS 251 Lab 3
Two dimensional array code
*/
#include <cstdlib>
#include <iostream>
#include <iomanip>
usingnamespace 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
initialize (rect);
cout << "The initial array is:\n";
// call print to print rect here
print (rect);
// call zero_row to zero all values in rect in row 1
//BBBBBBBBBBBBBBBBBBBBBBBBBBB
zero_row (rect, 0);
cout << "\n\nThe array with zeroed row 1 is:\n";
// call print to print rect here
print (rect);
// call zero_row to zero all values in rect in row 3
//BBBBBBBBBBBBBBBBBBBBBBBBBBBB
cout << "\n\nThe array with zeroed row 3 is:\n";
// call print to print rect here
print (rect);
// call zero_all to zero all values in rect
zero_all (rect);
cout << "\n\nThe array with all zeros is:\n";
// call print to print rect here
print (rect);
cout << "\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}
// 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++)
{
cout << "\n";
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])
{
int row, col;
int rect;
for (row = 0; row < 4; row++)
for (col = 0; col < 5; col++)
my_arr[row][col] = 0;
}
// sets all values of the given row in the 2 D array to zero
void zero_row (int a [4][5], int row)
{
for (row = 0; row < 4; row++)
a[row][5]= 0;
}
I can't seem to figure out how to zero out the whole row in the array. It has to zero out the first row in the first call. Then the 3rd row when its called again. Im guessing when you call it back in main, you tell it what row to zero out
I was thinking of it too simplified as we would see it rather than how the array would. So this still allows the columns to get their set values, but when you input a row when its called, it sets that row to 0. Thanks