Can similar code be written for 3 dimensions:
#include <exception>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
void display(long double **);
void de_allocate(long double **);
int m = 3; // ROWS.
int n = 5; // COLUMNS.
int main(void) {
long double **data;
try { // EXCEPTIONS.
data = new long double*[m]; //THE ROWS.
for (int j = 0; j < m; j++)
data[j] = new long double[n]; //THE COLUMNS
}
catch (std::bad_alloc) {
cout << "Could not allocate. Bye ...";
cin >>"";
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
data[i][j] = i + j;
display(data);
de_allocate(data);
return 0;
}
void display(long double **data) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
cout << data[i][j] << " ";
cout << "\n" << endl;
}
cout <<"Input any character to quit then press [ENTER]"<<endl;
cin >>" ";
}
void de_allocate(long double **data) {
for (int i = 0; i < m; i++)
delete[] data[i]; // DELETE THE COLUMNS
delete[] data; // DELETE THE ROWS
}
I am working on trying to get it to work for 3 dimensions + but I would like to see how others implement this.
Thanks yet again.