When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
7 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@final tangle
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
!format
!f must be used while replying to a message
!format
#include <time.h>
#include <iostream>
using namespace std;
class Coord {
public:
int x;
int y;
int z;
Coord() { x = y = z = 0; };
Coord(int x, int y, int z) : x(x), y(y), z(z) {}
void print() { cout << "(" << x << ", " << y << ", " << z << ")" << endl; }
};
class User {
protected:
string name;
public:
User() { random(); }
void random();
string getName() { return name; }
};
class Matrix {
public:
Matrix() { size = Coord(0, 0, 0), grid = nullptr; }
Matrix(Coord size);
void print();
Coord getSize() { return size; };
User*** getAddr() { return grid; };
~Matrix();
private:
Coord size;
User*** grid;
};
class Agent {
Matrix* matrix;
public:
Agent();
Agent(Matrix& matrix);
Coord search();
};
class Neo : public User {
public:
Neo() { name = "NEO"; }
};
// generating random character - do 3 times
void User::random() {
do {
name = " ";
for (int i = 0; i < 3; i++) {
char minc = 'A';
char maxc = 'Z';
name += minc + rand() % (maxc - minc + 1);
}
} while (name == "NEO");
};
// constructor that will create the 3dArray
Matrix::Matrix(Coord size) {
this->size = size;
grid = new User**[size.z];
for (int z = 0; z < size.z; z++) {
grid[z] = new User*[size.y];
for (int y = 0; y < size.y; y++) {
grid[z][y] = new User[size.x];
}
}
// creating a random place in the matrix to put NEO
int ranx = rand() % size.x;
int rany = rand() % size.y;
int ranz = rand() % size.z;
grid[ranx][rany][ranz] = new User*;
}
// print 3D array
void Matrix::print() {
for (int z = 0; z < size.z; z++) {
for (int y = 0; y < size.y; y++) {
for (int x = 0; x < size.x; x++) {
cout << grid[z][y][x].getName() << " ";
}
cout << endl;
}
cout << endl;
}
}
the issue is where I create a random place in the matrix to put Neo. how do I properly assign grid[ranx][rany][ranz]?