I need to be able to implement the boardX variables so that the board can call t
ID: 3837975 • Letter: I
Question
I need to be able to implement the boardX variables so that the board can call the variables into the spaces of the tic tac toe board. Can someone help me make a method that will help call the boardX variables.
tBoard::tBoard(){
board1 = BLANK;
board2 = BLANK;
board3 = BLANK;
board4 = BLANK;
board5 = BLANK;
board6 = BLANK;
board7 = BLANK;
board8 = BLANK;
board9 = BLANK;
ostream & operator<<(ostream& os, const tBoard& myTable)
{
os << " | 0 | 1 | 2 |" << endl
<< " +------------+" << endl
<< "0 | | | |" << endl
<< " +------------+" << endl
<< "1 | | | |" << endl
<< " +------------+" << endl
<< "2 | | | |" << endl
<< " +------------+" << endl;
return os;
}
Explanation / Answer
Note Points :
tBoard is a class that contains the variables as follows
//tBoard.h
//set a constant space for BLANK
#define BLANK ' '
class tBoard
{
private :
//private data variables
char board1;
char board2;
char board3;
char board4;
char board5;
char board6;
char board7;
char board8;
char board9;
public:
tBoard();
friend ostream & operator<<(ostream& os, const tBoard& myTable);
};
tBoard::tBoard()
{
board1 = BLANK;
board2 = BLANK;
board3 = BLANK;
board4 = BLANK;
board5 = BLANK;
board6 = BLANK;
board7 = BLANK;
board8 = BLANK;
board9 = BLANK;
}
ostream & operator<<(ostream& os, const tBoard& myTable)
{
//since the << is a friend function of tBoard class, the object myTable can directly access
//the data members of the class
os << " | 0 | 1 | 2 |" << endl
<< " +------------+" << endl
<< "0 |"<<myTable.board1<<"|"<<myTable.board2<<"|"<<myTable.board3<<endl
<< " +------------+" << endl
<< "1 |"<<myTable.board4<<"|"<<myTable.board5<<"|"<<myTable.board6<<endl
<< " +------------+" << endl
<< "2 |"<<myTable.board7<<"|"<<myTable.board8<<"|"<<myTable.board9<<endl
<< " +------------+" << endl;
return os;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.