i am totally stumped on what to do here. basically whats goin on is i have a 3D dynamic array and i need to have a cursor inside of it and move around on the inside. i do i go about doing that? like i said im completely stumped.
here is my code:
#include <iostream>
#include <conio.h>
#include "Definitions.h"
using namespace std;
class Darray{
protected:
int DEPTH,
ROW,
COL;
int*** array;
public:
Darray();
Darray(int depth, int row, int col);
~Darray();
Darray(const Darray& darray); //copy constructor
Darray& Darray::operator= (const Darray& darray); //assignment operator
void getDimensions(int DEPTH, int ROW, int COL);
void destroy();
void create();
void init();
void resetSize(int DEPTH, int ROW, int COL);
};
Darray::Darray()
{
DEPTH=0;
ROW=0;
COL=0;
array=NULL;
}
void Darray::create()
{
array = new int** [DEPTH];
for(int d=0; d<DEPTH; d++) {
*(array+d) = new int* [ROW];
for (int r=0; r<ROW; r++)
*(*(array+d)+r) = new int [COL];
}
}
Darray::Darray(int depth, int row, int col)
{
DEPTH = depth;
ROW = row;
COL = col;
create();
init();
}
Darray::~Darray()
{
destroy();
}
Darray::Darray(const Darray& darray)
{
DEPTH = darray.DEPTH;
ROW = darray.ROW;
COL = darray.COL;
create();
for(int d=0; d<DEPTH; d++)
for(int r=0; r<ROW; r++)
for(int c=0; c<COL; c++)
array[d][r][c] = darray.array[d][r][c];
}
Darray& Darray::operator= (const Darray& darray)
{
resetSize(darray.DEPTH, darray.ROW, darray.COL);
for(int d=0; d<DEPTH; d++)
for(int r=0; r<ROW; r++)
for(int c=0; c<COL; c++)
array[d][r][c] = darray.array[d][r][c];
return *this;
}
void Darray::destroy()
{
for (int d=0; d<DEPTH; d++)
{
for(int r=0; r<ROW; r++)
delete [] *(*(array+d)+r);
delete [] *(array+d);
}
delete [] array;
}
void Darray::init()
{
for(int d=0; d<DEPTH; d++)
for(int r=0; r<ROW; r++)
for(int c=0; c<COL; c++)
array[d][r][c] = 0;
}
void Darray::getDimensions(int DEPTH, int ROW, int COL)
{
cout << "The Depth is: " << DEPTH << " The Row is: " << ROW
<< " The Columns is: " << COL << endl;
}
void Darray::resetSize(int depth, int row, int col)
{
destroy();
DEPTH=depth;
ROW=row;
COL=col;
create();
init();
}
/***********************************************************************************/
class Grid : public Darray {
private:
int currentRow,
currentDepth,
currentCol;
public:
Grid();
void arrow_keys();
void UsDsFunction(int DEPTH, int ROW, int COL);
void print () const;
};
Grid::Grid()
{
int depth,
row,
col;
cout << "Enter the grid dimensions: " << endl;
cin >> depth >> row >> col;
// set up dimensions
DEPTH = depth;
ROW = row;
COL = col;
// set up position
currentRow = ROW / 2 + 1;
currentDepth = DEPTH / 2 + 1;
currentCol = COL / 2 + 1;
create();
}
void Grid::print () const
{
// makes grid
//makes top row or grid
for(int d=0; d<DEPTH; d++)
{
if(d<DEPTH)
{
cout << U_L;
cout << LINE;
for(int c=0; c<COL-1; c++)
{
cout << T_M;
cout << LINE;
}// end for
cout << U_R;
cout << "\n";
for( c=0; c<COL+1; c++)
{
cout << VERT_LINE;
cout << " ";
}// end vertical line first row
}cout << "\n";// end top of grid
// makes gird middle
for(int r=0; r<ROW-1; r++)
if(r<ROW)
{
cout << L_SM;
cout << LINE;
for(int c=0; c<COL-1; c++)
{
cout << M;
cout << LINE;
}// end for
cout << R_SM;
cout << "\n";
for( c=0; c<COL+1; c++)
{
cout << VERT_LINE;
cout << " ";
}cout << endl;
}// end middle of grid
// makes last line
if(d<DEPTH)
{
cout << L_L;
cout << LINE;
for(int c=0; c<COL-1; c++)
{
cout << L_MT;
cout << LINE;
}
cout << L_R;
}
cout << endl;
}//end last row
}
void Grid::UsDsFunction(int DEPTH, int ROW, int COL)
{
int num,
num2;
cout << "would you like to upsize, downsize or keep the dimensions the same? " <<
"\n\n";
cout << "Choose an option: " << endl;
cout << "1.) Upsize" << endl;
cout << "2.) Downsize" << endl;
cout << "3.) Keep the same" << endl;
cin >> num;
switch (num)
{
case 1:
resetSize(DEPTH, ROW, COL);
break;
case 2:
resetSize(DEPTH, ROW, COL);
break;
case 3:
cout << "Grid staying the same" << endl;
break;
}
}
void Grid::arrow_keys()
{
char key;
bool flag = false;
do {
key = getch();
switch (toascii(key)) {
case 96:
case 224:
flag = true;
break;
case 72: // up arrow
if (flag) {
cout << ACTIVE;
cout << endl;
flag = false;
}
else
cout << "try again. " << endl;
break;
case 77:
if (flag) {
cout << ACTIVE;
cout << endl;
flag = false;
}
else
cout << "try again. " << endl;
break;
case 75:
if (flag) {
cout << ACTIVE;
cout << endl;
flag = false;
}
else
cout << "try again. " << endl;
break;
case 80:
if (flag) {
cout << ACTIVE;
cout << endl;
flag = false;
}
else
cout << "try again. " << endl;
break;
case 13:
cout << "Enter" << endl;
break;
default:
cout << "try again. " << endl;
break;
}
} while (key != 13);
}
/******************************************************************************/
class Cell{
private:
bool visit,
active;
public:
Cell();
~Cell();
void fill();
};
Cell::Cell()
{
visit = 0;
active = 0;
}
Cell::~Cell()
{
}
//fill cell when visited
void fill()
{
}
/*******************************************************************************/
void main()
{
//Darray d;
Grid g;
Cell c;
//d.getDimensions(depth, row, col);
g.print();
g.arrow_keys();
//g.UsDsFunction(depth, row, col);
g.print();
}