#include using namespace std; const int ROWS = 5; // global variable for max size of int array const int COLS = 4; void ReadChars(char[][3],int rows, int cols); void WriteCharRows(char[][3], int rows, int cols); void WriteIntRows(int [][COLS], int rows, int cols); void WriteIntCols(int[][COLS], int rows, int cols); void WriteCharDiag(char[][3], int rows); int main() { int Nums[ROWS][COLS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; char Ch[3][3]; // a two dimensional character array ReadChars(Ch, 3, 3); WriteCharRows(Ch, 3, 3); WriteIntRows(Nums, ROWS, COLS); WriteIntCols(Nums, ROWS, COLS); WriteCharDiag(Ch, 3); return 0; } void ReadChars(char Ch[][3], int rows, int cols) { // walk through the character array read in values row by row int i, j; cout << "Please enter " << rows * cols << " characters " << endl; for (i = 0; i < rows; i ++) // for each row for (j = 0; j < cols; j++) // for each col element cin >> Ch[i][j]; // read in the value return; } void WriteCharRows(char Ch[][3], int rows, int cols) { int i, j; // walk through the character array writing out the values row by row cout << endl << " character array displayed row by row" << endl; for (i = 0; i < rows; i++) { for (j=0; j < cols; j++) cout << Ch[i][j] << " "; cout << endl; } return; } void WriteIntRows(int Nums[][COLS], int rows, int cols) { // walk through the integer array writing out the values row by row int i, j; cout << endl <<" integer array displayed row by row" << endl; for (i = 0; i < rows; i++) // for each row { for (j = 0; j < cols; j++) // for each col element cout << Nums[i][j] << " "; cout << endl; } return; } void WriteIntCols(int Nums[][COLS], int rows, int cols) { // walk through the integer array writing out the values col by col int i, j; cout << endl <<" integer array displayed col by col" << endl; for (j = 0; j < cols; j++) // for each col { for (i = 0; i < rows; i++) // for each row element cout << Nums[i][j] << " "; cout << endl; } return; } void WriteCharDiag(char Ch[][3], int rows) { // write out the upper left to lower right diagonal elements of the character array int i; cout << endl << " character array major diagonal elements" << endl; for (i = 0; i < rows; i++) cout << Ch[i][i]; cout << endl; return; }