Hi everybody, please i need your help. i try to implement a sudoku game with success as you can See hier under:
#include "sudoku.h"
#include <string>
using namespace std;
const char Sudoku::EMPTY_CELL = '0';
Sudoku::Sudoku()
{
for (int row = 0; row < SIZE; ++row)
{
for (int column = 0; column < SIZE; ++column)
{
grid[row][column] = EMPTY_CELL;
}
}
}
bool
Sudoku::setGridPosition(int row, int column, char value)
{
if (value == EMPTY_CELL)
{
grid[row][column] = value;
return true;
}
for (int c = 0; c < SIZE; ++c)
{
if (grid[row][c] == value)
return false;
}
for (int r = 0; r < SIZE; ++r)
{
if (grid[r][column] == value)
return false;
}
int brstart = row / 3 * 3; int brend = brstart + 2;
int bcstart = column / 3 * 3; int bcend = bcstart + 2;
for (int br = brstart; br <= brend; ++br)
for (int bc = bcstart; bc <= bcend; ++bc)
if (grid[br][bc] == value)
return false;
grid[row][column] = value;
return true;
}
bool
Sudoku::readStream(std::istream & input)
{
for (int row = 0; row < SIZE; ++row)
if (!readLine(row, input))
return false;
return true;
}
bool
Sudoku::readLine(int row, std::istream & input)
{
string line;
input >> line;
if (line.length() < 9)
return false;
for (int column = 0; column < 9; ++column)
setGridPosition(row, column, line[column]);
return true;
}
void
Sudoku::solve()
{
for (int row = 0; row < Sudoku::SIZE; ++row)
{
for (int column = 0; column < Sudoku::SIZE; ++column)
{
if( grid[row][column] == Sudoku::EMPTY_CELL )
{
for (char value = '1'; value <= '9'; ++value)
{
if(setGridPosition(row, column, value))
break;
}
}
}
}
}
ostream &
operator <<(ostream & os, Sudoku & sudoku)
{
string horizontalLine = "+-----------------------+";
for (int row = 0; row < Sudoku::SIZE; ++row)
{
if (row % 3 == 0)
os << horizontalLine << endl;
for (int column = 0; column < Sudoku::SIZE; ++column)
{
if (column % 3 == 0)
os << "| ";
os << sudoku.readGridPosition(row, column) << ' ';
}
os << "|" << endl;
}
os << horizontalLine << endl;
return os;
}
#include "sudoku.h"
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char * argv[])
{
cout << "Welcome to sudoku " << endl;
Sudoku sudoku;
if( argc > 1 )
{
fstream input(argv[1]);
input >> sudoku;
}
else
cin >> sudoku;
sudoku.solve();
cout << sudoku;
system("pause \n");
return 0;
}
I Create a new Project name "
Project_Sudoku_Test" when i let my method empty the Programm run without problem but if i try to implement my method without success i get this failure "In german" <<
error LNK2019: Verweis auf nicht aufgelöstes externes Symbol >>
in English i think it means
error LNK2019: unresolved external
#include "stdafx.h"
#include "CppUnitTest.h"
using namespace std;
#include "Sudoku.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
Sudoku sudoku ; string expected =
"+-----------------------+\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"+-----------------------+\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"+-----------------------+\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"| 0 0 0 | 0 0 0 | 0 0 0 |\n"
"+-----------------------+\n"
;
stringstream input;
input << "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl
<< "000000000" << endl;
bool success = sudoku.readStream(input);
Assert::IsTrue(success);
}
};
}
that is the Failure
error LNK2019: unresolved external
please cann you help me.
Thanks