1

Creating a crossword puzzle generator. The grid size is chosen by input and the grid will be generated. I'd like the grid to be an object with rows and columns but also a 2d array which will allow me to divide the grid into smaller sections for randomising between blank and numbered squares. I am not sure where to implement it. It has to be a 2d array as I will do dividing and inverting the layout.

Here is my Grid class with some methods. (And the rest)

class Grid 
{
    int rows; //x
    int columns; //y
    Square field;

public:
    void SetXY(int x, int y)
    {
        rows = x;
        columns = y;
        return;
    }
public:
    void DisplaySize()
    {
        cout << "Rows = ", rows, "Columns = ", columns;
    }
};

1 Answer 1

1

The simplest way to implement a 2D array is to use a std::array<std::array<>> or std::vector<std::vector<>> - depending on whether it needs to be a static or dynamically sized array.

But, you can also just use a one dimensional std::array or std::vector and then just get the second dimension by indexing like row*size_of_row+column.

Sign up to request clarification or add additional context in comments.

1 Comment

What is the best way of implementing the 2d array of sizes from my Grid object (rows and columns)? I tried doing this but the values must be constant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.