الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

إيجاد خطأ في كود لا أعلم ما هو

بدأه Dnawi في 5 مايو 2012 · 9 رد · 357 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

انا كتبت كود كامل ولله الحمد وبإذن الله سيعمل

للعبه الـ checkers

لم يظهر لي اي اخطاء

ولكن في وقت التشغيل run time يظهر لي خطأ لا اعلم ماهو

#include<iostream>
using namespace std;

#ifndef board_h
#define board_h

class board 
{
protected :

const int state_black;
const int state_white ;
const int state_board_m ;
const int state_board_im ;
const int state_black_k ;
const int state_white_k; // shows states of pieces on board																				  //  ( white, white_king, black, black_king and the board surface )
 int arr[8][8];   // 8 x 8 state type array it takes values : (black,white,board)


public :
	board () ;
	board (int state_b , int state_w , int state_b_m , int state_bo_i ,int state_b_k , int state_w_k )
		:state_black (state_b), state_white(state_w), state_board_m (state_b_m), state_board_im (state_bo_i), state_black_k(state_b_k),
		state_white_k (state_w_k) 
{
  int i, j;
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 2; j++) {
            arr[j]; 
		}
	}
	}


char fun_piece_wk()     // function to return white piece .
{
	return 'W';
}

char fun_piece_bk()     // function to return black_king piece .
{
	return 'B';
}

char fun_piece_w()     // function to return white piece .
{
	return 'w';
}

char fun_piece_b()     // function to return black piece .
{
	return 'b';
}

char fun_board_m()		// function to return checker movable board places .
{

	return '_';
}

char fun_board_im()		// function to show checker immovable board places .
{

	return ' ';
}

void king_check()				// transforms white checker to white king
{

	for(int i=0;i<1;i++)
	 for(int j=0;j<8;j++)
		 if(arr[j]==state_white)
		 {
			arr[j]= state_white_k;
		 }



}

void b_king_check()				// transforms black checker to black king
{
	for(int i=7;i<8;i++)
			 for(int j=0;j<8;j++)
				 if(arr[j]==state_black)
		 {
			arr[j]=state_black_k;
		 }

}

void print()
{


		cout<<"        0  1  2  3  4  5  6  7 "<< endl<< endl<< endl;    // No of columns

	for(int m=0;m<8;m++)							// loop to call functions to print pieces
	{
		cout<<"    "<<m<<"   ";				// No of rows
		for(int n=0;n<8;n++)
		{

			if(arr[m][n]==  state_white)
			{
				cout<<fun_piece_w()<<"  ";   // calling function to print   white piece == "w"
			}
			else if (arr[m][n]== state_black)
			{
				cout<<fun_piece_b()<<"  ";		// calling function to print   black piece == "b"

			}
			else if (arr[m][n]== state_white_k)
			{
				cout<<fun_piece_wk()<<"  ";		// calling function to print   white king piece == "W"

			}
			else if (arr[m][n]== state_black_k)
			{
				cout<<fun_piece_bk()<<"  ";		// calling function to print   black king piece == "B"

			}
			else if (arr[m][n]==state_board_m)
			{
				cout<<fun_board_m()<<"  ";			// calling function to print   board == "_" to show board places where checkers can move

			}
			else
				cout<<fun_board_im()<<"  ";		// calling function to print   board == " "  to show board places where checkers cannot move

			}
		cout << endl<< endl<< endl;
	} 
			 cout<< endl<<"     ================================="<< endl<< endl; 


}

};

#endif


//---------------------------------------------------------------


#include <iostream>
using namespace std ;

#ifndef move_h
#define move_h

class move : public board 
{
private :
int mf_row,mf_column,bmf_row,bmf_column;		// Move from 
int mt_row,mt_column,bmt_row,bmt_column;		// Move to 


public :
	move () : board () 
	{
		mf_row = 0 ;
	 mf_column = 0 ;
	 bmf_row = 0 ;
	 bmf_column = 0 ;		
	 mt_row = 0 ;
	 mt_column = 0 ;
	 bmt_row= 0 ;
	 bmt_column = 0 ;
	}
	move ( int mf_r,int mf_c,int bmf_r,int bmf_c ,int mt_r, int mt_c, int bmt_r,int bmt_c ) : board	()
	{
	 mf_row =  mf_r ;
	 mf_column = mf_c ;
	 bmf_row = bmf_r ;
	 bmf_column = bmf_c ;		
	 mt_row =  mt_r ;
	 mt_column = mt_c ;
	 bmt_row= bmt_r ;
	 bmt_column = bmt_c ;
	}



};

#endif 


// ------------------------------------------------------------------


#include<iostream>
#include "board.h"
#include "move.h"
using namespace std;


int main ()             
{l ;
	move v ;
	v.moveit ();


	return 0;

}

رجوا مساعدتي جزاكم الله عني خير الجزاء وفرج هم من اعانني فيه وجعله في ميزان حسناته

لا اسامح من ياخذ هذا الكود وينسبه لنفسه ( بلا إذن مني ) فقد بذلت على هذا المشروع مجهودا متعبا :(

شكرا لكم

تم تعديل هذه المشاركة بواسطة Dnawi في 5 مايو 2012 في 15:59

#2

قم باضافة كود الخطأ

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#3

هذا ما يظهر لي في وقت run

لم افهم ماذا يعني

1>------ Build started: Project: hndi, Configuration: Debug Win32 ------
1>Linking...
1>checker.obj : error LNK2019: unresolved external symbol "public: __thiscall board::board(void)" (??0board@@QAE@XZ) referenced in function "public: __thiscall move::move(void)" (??0move@@QAE@XZ)
1>C:\Users\DINA\Documents\Visual Studio 2008\Projects\hndi\Debug\hndi.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\DINA\Documents\Visual Studio 2008\Projects\hndi\hndi\Debug\BuildLog.htm"
1>hndi - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#4

في الملف move.h قم باضافة include "board.h"

المشكله هنا هي عندما يحاول الكلاس move استدعاء الكلاس board لكي يبنيه فانه لا يجده

تحياتي

1

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#5

اشكر لك مساعدتك

ولكن قمت باضافته ولم يتغير شيء

#6

ماهي الملفات الموجوده في برنامجك؟

دالة الmain داخل اي ملف ؟

فنلفترض ان دالة الmain هي بداخل الملف move.cpp في هذه الحاله يجب ان تضيفي ايضا include "move.h" الى هذا الملف

اطبعي رسالة الخطا فقد تكون مختلفه عن السابقه

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#7

قمت باضافة "board.h" داخل move.h

وقمت باضافه "board.h" و "move.h"

في الملف checker.cpp الذي يوجد به الـ main

وهذا ماخرج لي

1>------ Build started: Project: checker, Configuration: Debug Win32 ------
1>Linking...
1>checker.obj : error LNK2019: unresolved external symbol "public: __thiscall board::board(void)" (??0board@@QAE@XZ) referenced in function "public: __thiscall move::move(void)" (??0move@@QAE@XZ)
1>C:\Users\DINA\Documents\Visual Studio 2008\Projects\hndi\Debug\checker.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\DINA\Documents\Visual Studio 2008\Projects\hndi\hndi\Debug\BuildLog.htm"
1>checker - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

اعتذر عن الازعاج بشده

#8
mental-driller كتب:

في الملف move.h قم باضافة include "board.h"

المشكله هنا هي عندما يحاول الكلاس move استدعاء الكلاس board لكي يبنيه فانه لا يجده

تحياتي

أو

I don't see the implementation of the board constructor anywhere

و

But then, it's 1300 lines of code, so it's not like I looked very hard.

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#9

غير هذا السطر

board () ;

الى

board () {}

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#10

وجدت فعلا ان الخطأ في board constructor

وقد صححته بهذه الطريقه ولم يظهر لي خطأ ولله الحمد

board () : state_black (0) ,state_white(0) , state_board_m (0) , state_board_im (0) , state_black_k (0) ,state_white_k(0) 
	{
	}

شكرا جزيلا جزاكم الله عني خيرا

مواضيع مشابهة