Question: C++ N Queen - Backtracking HELP Program should have two files main.cpp and ChessBoard.h Below is the starter main.cpp file: // Driver program for the

C++ N Queen - Backtracking HELP

Program should have two files main.cpp and ChessBoard.h

Below is the starter main.cpp file:

// Driver program for the ChessBoard class // which solves the N-Queens problem for // board sizes of 4 to 12.

#include #include "ChessBoard.h" using namespace std;

int main() { int choice;

do { cout > choice;

if (choice > 12 || choice 12 || choice

// Create a board of the input size ChessBoard myBoard(choice);

// Attempt to solve the N-Queens Problem if (!myBoard.solve()) cout

cin.ignore(); cin.get();

return 0; }

Here are the details to finish the lab

C++ N Queen - Backtracking HELP Program should have two files main.cpp

and ChessBoard.h Below is the starter main.cpp file: // Driver program for

Below is the placeQueens() helper:

the ChessBoard class // which solves the N-Queens problem for // board

Please use the same functions names so I can understand the code. thank you

boardSize -Tracks the size of the board. Valid sizes are 4 through 12. For example, if boardSize is 10 the board is 10x10. p -Implements the provided recursive laceQueens (int, int) pseudocode (see last page) to find placements for the queens on the board. . ChessBoard () - Default constructor which sets the board size to 8. . ChessBoard (int) - Constructor which sets the board size to the given int. If the int12 it sets the size to 12. solve() - Non-recursive function that calls the recursive placeQueens (). Returns true if the board was solve successfully. e displayBoard) -Displays the board to the screen. Queens are displayed as a Q. Blank squares should be displayed as a single *. Individual squares on the board display with 1 space between them. So, a 4x4 board is displayed as: Additional Requirements * ChessBoard must be implemented as ChessBoard.h and ChessBoard.cpp . Your ChessBoard must work with the supplied main.cpp. e You must implement placeQueens () recursively based on the algorithm given in the pseudocode. Iterative solutions or recursive solutions drastically different from the pseudocode will not be accepted. Your project must meet the requirements of the course style guide. Turn In Upload your ChessBoard.h and ChessBoard.cpp prior to the due date. placeQueens (int row, int column) if (column >= board size) The board is filled, problem is solved. else while (unconsidered rows exist in the given column and the problem is unsolved) Starting with the current row, find the next square in the given column that is not under attack by a queen placed in a previous column. if (such a square exists) Place a queen in the unattacked square. Do a recursive call to try and place queens in subsequent columns: if (placeQueens (firstRow, column1)) This placement of the queen above didn't work for subsequent columns. Remove the queen placed above. Move to the next row. else The problem is successfully solved else No unattacked square found for a queen in this column. This attempt is unsuccessful. return true if successful, false if not

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!