//PID : 5664816
/*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.
*/
#include <iostream>
#include "cell.h"
using namespace std;
//create cell constructor
cell::cell(int x, int y, int z)
{
this->firDimension = x;
this->secDimension = y;
this->thirDimension = z;
}
//cell destructor
cell::~cell()
{
}
Main.cpp
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include "cell.h"
using namespace std;
int main(void)
{
// declare variable for array dimension
int firstDimension = 0;
int secondDimension = 0;
int thirdDimension = 0;
string choice;
//enter the values
while (choice !="N")
{
cout<<"Please enter the sizes of the array"<<endl;
cell *nArray;
cout << "Enter first dimension: ";
cin >> firstDimension;
cout << "Enter second dimension: ";
cin >> secondDimension;
cout << "Enter third dimension: ";
cin >> thirdDimension;
//create new array and pass the new values
// srand ((unsigned)time(NULL));
nArray= new cell(firstDimension, secondDimension, thirdDimension);
// nArray[firstDimension,secondDimension,thirdDimension]=rand ()%10;
nArray->createMyarray();
srand ((unsigned)time(NULL));
//delete array
delete nArray;
cout<<'\n';
cout<< "Would you like to continue [Y/N] ?" ;
cin>>choice;
if (choice == "n" || choice=="N")
{
choice = "N";
}
}
return 0;
}
cell.cpp
#include <iostream>
#include "cell.h"
using namespace std;
//create cell constructor
cell::cell(int x, int y, int z)
{
this->firDimension = x;
this->secDimension = y;
this->thirDimension = z;
}
//cell destructor
cell::~cell()
{
}
No comments:
Post a Comment