I've been working on a class project program using pointers and arrays with pointer offset notation (I think). Below is the diagram used for the project
Prompt for project
*The shaded boxes represent pointers. The unshaded boxes represent a dynamically allocated two dimensional int array. Your program cannot create named identifiers for any of the unnamed items. The number of rows and the number of columns will be user input. The ellipses in the diagram represent that the sizes of the rows and columns are variable. The vertical array is an array of pointers. Each of the vertical array elements points to a one dimensional array of integers.

In your program only refer to the integer array through the pointers represented by s, t, u, and v. When passing to functions you must always pass these pointers. You cannot dereference actual parameters in a function call. Nor can you dereference pointers and assign them to variables just in order to work with them.*
#include <iostream>
using namespace std;
void fillArray(int **pArray, int rows, int columns)
{
for(int row = 0; row < rows; row++)
{
*(pArray + row) = new int;
cout << "Enter " << " row " << row + 1<< endl;
for(int col = 0; col < columns; col++)
{
cin >> *(*(pArray + row) + col);
}
}
}
void printArray(int **pArray, int rows, int columns)
{
for(int row = 0; row < rows; row++)
{
cout << "Row " << row + 1 << endl;
for(int col = 0; col < columns; col++)
{
int num = *(*(pArray + row) + col);
cout << num << " ";
}
cout << endl;
}
}
void reverseArray(int **pArray, int rows, int columns)
{
for(int row = 0; row < rows; row++)
{
cout << "Reversed Row " << row + 1 << endl;
for(int col = columns - 1; col >= 0; col--)
{
int num = *(*(pArray + row) + col);
cout << num << " ";
}
cout << endl;
}
}
int main()
{
int rows;
int columns;
cout << ("Input number of rows: ");
cin >> rows;
cout << ("Input number of columns: ");
cin >> columns;
int **pArray; //Initialize array
int ****s; //Initialize pointers s, t, u, v
**s = pArray;
int ****t;
*t = *s;
int ****u;
**u = pArray;
int ****v;
*v = *u;
pArray = new int*[rows]; //create pointer to rows. 1st level of indirection
*pArray = new int[columns]; //create pointer to columns. 2nd level of indirection
fillArray(pArray, rows, columns);
printArray(pArray, rows, columns);
reverseArray(pArray, rows, columns);
//Loop to terminate program
while (true)
{
cout << "\nEnter letter \'q\' to terminate program\n";
char c;
cin >> c;
if(c == 'q')
break;
}
}
Sorry for the poor code formatting. I couldn't understand how to copy and paste in code block.
So my question is, how do I implement the diagram with my program. I started with the basics of creating the array using pointer offset and labeling it with it's own name.
I believe I have to change all of my references to work with the pointer variables 's, t, u, v.' Any help is appreciated.
{}icon (or press Ctrl+K) and it will be formatted properly. Maybe it won't work properly if you use tabs instead of spaces, though.int ****s: if there is no way around excessive pointing, I would very strongly recommend that youtypedefthe levels of array, so that we don't lose you to Codethulhu.