#include #include using namespace std; int **make_mult_table(const int row_count, const int col_count); void print_table(int **rows, const int row_count, const int col_count); void delete_table(int **rows, const int row_count, const int col_count); int main() { int **table = make_mult_table(3, 4); print_table(table, 3, 4); delete_table(table, 3, 4); return 0; } int **make_mult_table(const int row_count, const int col_count) { // Dynamically allocate an array of pointers to integers. int **rows = new int*[row_count]; // For each row ... for (int r = 0; r < row_count; r++) { // ... dynamically allocate a row of integers. rows[r] = new int[col_count]; // For each element of a row ... for (int c = 0; c < col_count; c++) { // ... calculate its value. rows[r][c] = (r+1)*(c+1); } } // Return the pointer to a pointer to an integer. return rows; } void print_table(int **rows, const int row_count, const int col_count) { // For each row of the table ... for (int r = 0; r < row_count; r++) { // ... get the pointer to the row of integers. int *row = rows[r]; // For each element of a row ... for (int c = 0; c < col_count; c++) { // ... print it. cout << setw(3) << row[c]; } cout << endl; } } void delete_table(int **rows, const int row_count, const int col_count) { // For each row of the table ... for (int r = 0; r < row_count; r++) { // ... delete the row pointed to by the row pointer. delete[] rows[r]; } delete[] rows; }