如何在VS 12上制作SUdokuTest [英] How to made SUdokuTest on VS 12

查看:57
本文介绍了如何在VS 12上制作SUdokuTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要你的帮助。我尝试成功实现一个数独游戏,你可以在下面看到:

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;
}





我创建一个新项目名称 Project_Sudoku_Test 当我让我的方法清空程序运行没有问题,但如果我尝试实现我的方法没有成功我得到这个失败在德国<< 错误LNK2019:Verweis aufnichtaufgelöstesexternes符号>> ;

英文我认为这意味着错误LNK2019:未解决的外部



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);
		}

	};
}







即失败错误LNK2019:未解决的外部

请帮帮我。

谢谢




that is the Failure error LNK2019: unresolved external
please cann you help me.
Thanks

推荐答案

请看看:



http:/ /msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx [ ^ ]



并检查更正和你的职能/班级的关系......
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...


这篇关于如何在VS 12上制作SUdokuTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆