Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The game Tic-Tac-Toe (or Naughts and Crosses) is an ancient game in which 2 play

ID: 3653530 • Letter: T

Question

The game Tic-Tac-Toe (or Naughts and Crosses) is an ancient game in which 2 players alternate turns palcing either X's or O's on 3*3 square grid. One Player places X's on the grid and the opposing player places O's. The first player to place 3 consecutive X's (or O's) on any row, column or diagonal of the grid wins the game. If all 9 grid cells are occupied without either player winning, the game is declared a draw. Write a C++ function that takes a two-dimensional 3*3 array of charaacters representin a tic-tac-toe game in progress and determines the current state of the game: player X has won, player O has won, the game is a draw or none of those. Your function should return a single character as follows: 'X' if player X has won the game, 'O' if player O has won the gmae, 'D' if the game is a draw (all cells occupied but neither layer has won) and '*' if none of these conditions exist. (Hint: use a for loop that compares each element of the diagonal with the elements of tits intersecting row and column, then check the diagonals) Write a main() driver to verify that your function is correct. Your main program should do the following: 1) declare a 3*3 character array, 2) use a loop to read in values for each of the 3 rows of the grid (use '-' to indicate a black cell), 3) print out the contents of the grid as 3 rows of 3 values, 4) call your function with the array as an argument, and 5) output an appropriate message declaring the state of the game (as returned by your function).

Explanation / Answer

#include #include #include using namespace std; class TicTacToe { public: TicTacToe(); // constructor int Pick_Player(); // member function int Pick_Row(); // member functions int Pick_Column(); // member functions int Check_Board(); // member function void Choice_by_Player(int); // member functions void Choice_of_Row(int); // member functions void Choice_of_Column(int); // member functions void Tic_Tac_Toe_Board(); // member functions bool Check_Move(int,int); // member functions private: int row; int column; int player; int board[3][3]; char display_board[3][3]; }; TicTacToe::TicTacToe()//:row(0):column(0):player(1):board(0)(0):display_board(' ')(' ') { row = 0; column = 0; player = 1; int i = 0; int j = 0; for ( i = 0; i < 3; i++) { for ( j = 0; j < 3; j++) { board[i][j] = 0; display_board[i][j] = ' '; } } } int TicTacToe::Pick_Player() { return player; } int TicTacToe::Pick_Row() { return row; } int TicTacToe::Pick_Column() { return column; } void TicTacToe::Choice_by_Player(int a) { player = a; } void TicTacToe::Choice_of_Row(int b) { row = b; } void TicTacToe::Choice_of_Column(int c) { column = c; } bool TicTacToe::Check_Move(int row, int column) { row = 0; column = 0; if ( row != 0 && row != 1 && row != 2 ) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote