Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview For this assignment, write a C++ program that prints all solutions of the N-queens problem for a given positive value of N. In the

Overview

For this assignment, write a C++ program that prints all solutions of the N-queens problem for a given positive value of N. In the N-queens problem, the goal is to place N queens on an N-by-N chess board so that no two queens are on the same row, column, or diagonal. Note that there are 2 answers to the 4-queens problem, 92 for 8-queens, and 724 for 10-queens. Don't choose big numbers.

Specifications

Your program must solve the N-queens problem using a recursive function. You need to implement a ChessPuzzle class with the member data and member functions specified in the following header file (ChessPuzzle.h).

#ifndef CHESSPUZZLE_H

#define CHESSPUZZLE_H

#include

#include

using namespace std;

class ChessPuzzle

{

public:

ChessPuzzle(int size = 8); //initializes all entries to 0

void printBoard() const;

bool canPlaceQueen(int row, int col);

bool inBoard(int row, int col);

void eightQueens(int row, int & solutions);

private:

vector< vector > board;

int N;

};

#endif

Implement all member functions in a separate source code file (e.g., ChessPuzzle.cpp). Test your recursive function using the following test file (ChessPuzzleMain.cpp).

#include "ChessPuzzle.h"

int main()

{

int size;

cout << "Enter the size of the board: ";

cin >> size;

ChessPuzzle myPuzzle(size);

int numberOfSolutions = 0;

myPuzzle.eightQueens(0, numberOfSolutions);

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

Can ML functions that deal with scalar numerics be generic?

Answered: 1 week ago