oop using c++ Create a class TicTacToe that will enable you to write a complete
ID: 3617909 • Letter: O
Question
oop using c++ Create a class TicTacToe that will enable you to write a complete program to play the game of Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array of integers. The constructor should initialize the empty board to all zeros. Allow two human players. Whenever the first player moves, place a 1 in the specified square, and place a 2 wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game has been won and whether it is a draw. The details are given below: The class should contain as its private data a 3 by 3 array of integers called board. A constructor should initialize the empty board to all zeroes. A method called Pl_move() will place a 1 in the specified position. This method shall take the position as an argument and returns nothing. A method called P2_move() will place a 2 in the specified position. This method shall take the position as an argument and returns nothing. Make sure that each move must be to an empty square. A method called EndGame() should determine after each move whether the game has been won or is a draw. This function should return a char value to decide whether to end the game or continue. A method called askNumber() should ask the user to enter the number and generate an error message if the number is out of range (not between 0 and 8 - look below to see how you are going to display your board). It should implement the logic to keep asking the user for a number until he enters a correct number. This function will return the number entered by the user. A displayBoard() Function should display the updated board to the players after each move in the same format as given in the instructions function below. A non-member function called instructions () is implemented below which will be called directly in main at the start of the program. Note: You may want to write some more functions in the class in order to make the code easier to write. For example, you may add a function validMovef) to check whether a move to a certain position is valid or not; a board_full() function to check whether the board is full or not. You might want to add a function to see if there is any winner or if the game is withdrawn. These are all optional and only if you want to add them to your code.Explanation / Answer
please rate - thanks be sure to put your instruction code in the instructions #include using namespace std; class TicTacToe {public: TicTacToe(); void initializeBoard(); void instructions(); void displayBoard();/*gets input from user returns character numberof location chosen by user*/ char getInput( char marker);/* mark character marker of player onchosen character pos of board*/ void markBoard(char pos, char marker);/*checks to see if someonehas won returns true or false*/ bool gameOver(); /*checks to see if someone won on rows ofboard*/ bool checkHorizontal( char marker);/*checks to see if someone wonon columns of board*/ bool checkVertical( char marker);/*checks to see if someone won ondiagonal of board*/ bool checkDiagonal( char marker);/*checks to see if players havetied*/ bool checkTie();/*prints winner as marker or ties*/ void printWinner(char marker);/*checks to see if selected locationis available returns false when location has already been taken oris an invalid number*/ bool validMove( charpos); private: char board[3][3]; }; int main() { char p1,p2, exit; TicTacToe a; a.instructions(); a.displayBoard(); while(true) { //player 1's turn p1 = a.getInput('X'); a.markBoard( p1, 'X'); a.displayBoard(); if (a.gameOver()) //if player 1 wins break out of loopbreak break; //player 2's turn p2 = a.getInput('O'); a.markBoard( p2, 'O'); a.displayBoard(); if (a.gameOver()) //if player 2 wins break out of loop break; } system("pause"); return 0; } /*checks to see if selected location is available returns falsewhen location has already been taken or is an invalid number*/ TicTacToe::TicTacToe() { char count('0'); for (int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.