The following is incomplete code, but it is all I have written. The idea is to solve the "n queens" problem, where n is the number of queens, and the dimensions of a chessboard (e.g., 8 queens on an 8x8 board).
The code as I have written it will allocate an 11x11 square, and then ask for the user to remove (11-n) columns and rows, n being the above.
I keep getting an error when I run the program. It compiles, but when I enter a number to deallocate the squares, it turns up an error and I have to break the debugging.
The code is below:
chessboard.h
Code:
#pragma once#include "Row.h"
#include "Column.h"
class Chessboard
{
private:
Row *row[11];
public:
Chessboard(void);
~Chessboard(void);
void allocateTiles();
void removeTiles(int num);
};
chessboard.cpp
Code:
#include "Chessboard.h"
Chessboard::Chessboard(void)
{
}
Chessboard::~Chessboard(void)
{
}
void Chessboard::allocateTiles()
{
for (int c=0; c<11; c++)
row[c] = new Column[11];
return;
}
void Chessboard::removeTiles(int num)
{
for(num; num<11; num++)
delete row[num];
return;
}
row.h
Code:
#pragma onceclass Row
{
private:
int rowNum;
public:
Row(void);
~Row(void);
void setRowNum(int num);
int getRowNum();
};
row.cpp
Code:
#include "Row.h"
Row::Row(void)
{
}
Row::~Row(void)
{
}
void Row::setRowNum (int num)
{
rowNum = num;
return;
}
int Row::getRowNum()
{
return rowNum;
}
column.h
Code:
#include "Row.h"
#pragma once
class Column: public Row
{
private:
int colNum;
public:
Column(void);
~Column(void);
void setColNum(int num);
int getColNum();
};
column.cpp
Code:
#include "Column.h"
Column::Column(void)
{
}
Column::~Column(void)
{
}
void Column::setColNum (int num)
{
colNum = num;
return;
}
int Column::getColNum()
{
return colNum;
}
main.cpp
Code:
#include "Chessboard.h"#include <iostream>
using namespace std;
int main()
{
Chessboard c;
int queens;
cout << "How many queens would you like to calculate for? ";
cin >> queens;
c.removeTiles(queens);
system("pause");
return 0;
}