Question: N queen problem for c++. It must include the following functions: bool** ReadChessboard(char* filepath, int& num_rows, int& num_cols); void PrintChessboard( bool** board, int num_rows, int
N queen problem for c++.
It must include the following functions:
bool** ReadChessboard(char* filepath, int& num_rows, int& num_cols);
void PrintChessboard( bool** board, int num_rows, int num_cols);
int main(int argc, char* argc[]);
Here is some of the code provided. I need the code for where it say "Modify and enter your code here."
#include
#include
using namespace std;
bool** ReadChessboard(char* filepath, int& num_rows, int& num_cols)
{
fstream infile;
infile.open(filepath);
infile >> num_rows;
infile >> num_cols;
/////////////////////////////////////////////////////////////////
// Modify and enter your code here, to create board with adding
// queens into the board.
return NULL;
/////////////////////////////////////////////////////////////////
}
void PrintChessboard(bool** board, int num_rows, int num_cols)
{
cout << "Print chess board:" << endl << endl;
/////////////////////////////////////////////////////////////////
// Enter your code here, to print chess board with queens.
// * " Q" to print a queen, and
// * " ." to print an empty cell.
/////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////
// Add your own functions if you need
/////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
if(argc <= 1)
{
cout << "Need the input file containing chess board size and queen locations." << endl;
return 0;
}
int num_rows;
int num_cols;
bool** board = ReadChessboard(argv[1], num_rows, num_cols);
PrintChessboard(board, num_rows, num_cols);
bool is_nqueens = false;
bool there_are_attacks = false;
/////////////////////////////////////////////////////////////////
// Enter your code here.
// If you want create your own functions
/////////////////////////////////////////////////////////////////
if(is_nqueens)
cout << "Solution to the N Queen Problem? Yes" << endl << endl;
else
cout << "Solution to the N Queen Problem? No" << endl << endl;
if(there_are_attacks)
{
cout << "There is at least one queen attacking other queen(s)." << endl;
/////////////////////////////////////////////////////////////////
// Enter your code to print list of queens attacking other queens
/////////////////////////////////////////////////////////////////
}
else
{
cout << "There is no queen attacking other queen(s)." << endl;
}
/////////////////////////////////////////////////////////////////
// Enter your code to delete dynamically allocated memories
/////////////////////////////////////////////////////////////////
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
