Question: Develop a program that builds a three - dimensional array ( dynamically ) to point to Cell Objects. Make sure the Cell object's keep track

Develop a program that builds a three-dimensional array (dynamically) to
point to Cell Objects. Make sure the Cell object's keep track of their (x,y,z)
location and contains a dynamic array (3 elements) to function pointers. Use
a tick function to animate the array, printing the cells location and call a
function from the array. The function can be static functions of the class.
Make sure you exercise the creating and deleting of the array. You must use
separate files for the Cell header and implementation files and where main is
located. Make sure to include appropriate pragmas for conditional
compilation of code.
Filed to be Created
Cell
Cell.h
main
Sample code:
Cell.H
#pragma once
class Cell {
public:
Cell(int x, int y, int z);
~Cell();
void tick();
static void function1(int x, int y, int z);
private:
int x, y, z;
int* dynamicArray;
static void internalFunction(int x, int y, int z);
};
Cell.cpp
#include "Cell.h"
#include
Cell::Cell(int x, int y, int z) : x(x), y(y), z(z){
dynamicArray = new int[3];
}
Cell::~Cell(){
delete[] dynamicArray;
}
void Cell::tick(){
std::cout << "Cell at ("<< x <<","<< y <<","<< z <<") is
ticking." << std::endl;
Cell::function1(x, y, z);
}
void Cell::function1(int x, int y, int z){
std::cout << "Function 1 called from Cell at ("<< x <<","<< y
<<","<< z <<")."<< std::endl;
}
void Cell::internalFunction(int x, int y, int z){
std::cout << "Internal function called from Cell at ("<< x <<",
"<< y <<","<< z <<")."<< std::endl;
}
Main.cpp
int *** buildArray(int x, int y, int z)
{
int ***tmp;
tmp = new int**[z];
for (int aZ =0; aZ < z; aZ++){
tmp[aZ]= new int*[y];
for (int aY =0; aY < y; aY++)
tmp[aZ][aY]= new int [x];
}
return tmp;
}
void populateArray(int ***A, int x, int y, int z)
{
int i, j, k;
for (i=0; i < z; i++)
for (j=0; j < y; j++)
for (k=0; k < x; k++)
A[i][j][k]= rand()%10;
}
void printArray(int ***A, int x, int y, int z)
{
int i, j, k;
cout << "Printing array of size z ="<< z <<" y ="<< y <<" x ="<< x << endl <<
endl;
for (i =0; i < z; i++)
{
cout <<" z["<< i <<"]"<< endl;
for (j =0; j < y; j++)
{
for (k =0; k < x; k++)
cout << A[i][j][k]<<"";
cout << endl;
}
cout << endl;
}
}
int *** deleteArray(int***A, int x, int y, int z)
{
for (int aZ =0; aZ < z; aZ++){
for (int aY =0; aY < y; aY++)
delete [] A[aZ][aY];
delete [] A[aZ];
}
delete [] A;
return NULL;
}
bool AgainArray(int* x, int* y, int* z)
{
char ch;
cout <<" Try again to build new array - y or n :";
cin >> ch;
ch = toupper(ch);
if (ch !='Y') return false;
cout << "Enter value for z:";
cin >>*z;
cout << "Enter value for y:";
cin >>*y;
cout << "Enter value for x:";
cin >>*x;
return true;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!