These are my instructions:
- create a class containing a 10x10 two-dimensional array of characters.
- class must have a constructor that puts the '.' character in each element.
- In main, I must allow the user to enter an 'X' into six different spaces in the 2D array.
(we're eventually making a simple minesweeper game, but this is the first assignment)
I have no idea how to set up a 2D array in a class. I've attempted different things, but I'm not sure where in the constructor I would initialize the array or how it is suppose to look. I don't even know if the private variables are suppose to be an array or values for an array.
Are there any examples of this type of set up? We haven't learned pointers yet, so I need a simple explanation. Here is my code so far:
sweeper.h
class Sweeper
{
public:
const static int row=10;
const static int col=10;
Sweeper(char b); //constructors
Sweeper();
void set(char b); //mutators
void set_box(char b);
char get_box() const; //accessors
friend ostream& operator<<(ostream& os, const Sweeper& aSweeper);
private:
char m_box[row][col];
};
sweeper.cpp
Sweeper::Sweeper(char b) //constructor
{
set(b);
}
Sweeper::Sweeper() //default constructor
{
set('.');
}
void Sweeper::set(char b) //mutators
{
set_box(b);
}
void Sweeper::set_box(char box)
{
m_box[row][col] = box;
}
char Sweeper::get_box() const //accessors
{
return(m_box[row][col]);
}
I'm a bit lost. I'm using a model of a class that the professor gave us, but it's not an array.