Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hi everybody, please i need your help. i try to implement a sudoku game with success as you can See hier under:
/*
	 * sudoku.cpp
	 *
	 */
	
	#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; // note: integer division!
	    int brend = brstart + 2;
    int bcstart = column / 3 * 3; // note: integer division!
	    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;
}
        /*
	 * sudokuMain.cpp
	 */
	
	#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 ;//=  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
Posted 21-Apr-13 2:46am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please have a look to:
 
http://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx[^]
 
and check the correction and the relationship of your functions / classes...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 21 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100