Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the main, ReadBoard, Show_GameState, Winner, PlayerMarks Write the C++ CODE. Purpose: Write a C++ program to accept a string that encodes the markings on

Write the main, ReadBoard, Show_GameState, Winner, PlayerMarks Write the C++ CODE. Purpose: Write a C++ program to accept a string that encodes the markings on a 3x3 tic-tac-toe board. The program must display the 2-dimensional tic-tac-toe board. The program must also announce the state of the game: NEW GAME -- when the board is empty. WINNER IS X -- when player X is the winner. WINNER IS O -- when player O is the winner. IN PROGRESS -- when no player has won and game not completed. DRAW -- when no player has won, and game is completed. Specification: +--------------+ | | | program | board_markings | |--------> game_status ------------->| tictactoeA | | |--------> tictactoeBoard | | +--------------+ Examples (Test Cases): Board Markings: BBBBBBBBB GAME STATUS: NEW GAME GAME BOARD: ---+---+--- | | ---+---+--- | | ---+---+--- | | ---+---+--- Board Markings: XBXBOOOBX GAME STATUS: IN PROGRESS GAME BOARD: ---+---+--- X | | X ---+---+--- | O | O ---+---+--- O | | X ---+---+--- Board Markings: XXXBOOOBX GAME STATUS: WINNER IS X GAME BOARD: ---+---+--- X | X | X ---+---+--- | O | O ---+---+--- O | | X ---+---+--- Board Markings: XXOOOXXOX GAME STATUS: DRAW GAME BOARD: ---+---+--- X | X | O ---+---+--- O | O | X ---+---+--- X | O | X ---+---+--- 

tictactoeA function header file

#include  #include  #include  using namespace std; // KEEP THESE pre-processor directives. #ifndef TTT_GAMESTATE #define TTT_GAMESTATE enum GameSTATE {NEW, IN_PROGRESS, X_WIN, O_WIN, DRAW}; #endif //---------------------------------------------------------------------------- // Function: Convert board marks to 9-character string. // Example: Diagonal X board is string "XBBBXBBBX" //---------------------------------------------------------------------------- string BoardMarks(char Board[][3]); //---------------------------------------------------------------------------- // Function: Read 9 marks for 3x3 tictactoe board from open input stream. //---------------------------------------------------------------------------- void Read_Board(istream & inF, char Board[][3]); //---------------------------------------------------------------------------- // Function: Display/Write board to output stream as 3x3 grid. // NOTE: Grid is indented the #spaces specified by the leftMargin. //---------------------------------------------------------------------------- void Show_Board(ostream & outF, char Board[][3], int leftMargin=12); //---------------------------------------------------------------------------- // Function: Announce the state of the game. //---------------------------------------------------------------------------- void Show_GameState(GameSTATE gameState); //---------------------------------------------------------------------------- // Function: Count the number of marks Player (X or O) has on the board. //---------------------------------------------------------------------------- int PlayerMarks(char Player, char Board[][3]); //---------------------------------------------------------------------------- // Function: Determine whether Player (X or O) has won the game. //---------------------------------------------------------------------------- bool Winner(char Player, char Board[][3]); 

tictactoeA function stubs

#include  using namespace std; // KEEP THESE pre-processor directives. #ifndef TTT_GAMESTATE #define TTT_GAMESTATE enum GameSTATE {NEW, IN_PROGRESS, X_WIN, O_WIN, DRAW}; #endif //---------------------------------------------------------------------------- // Function: Convert board marks to 9-character string. // Example: Diagonal X board is string "XBBBXBBBX" //---------------------------------------------------------------------------- string BoardMarks(char Board[][3]) { }//BoardMarks //---------------------------------------------------------------------------- // Function: Read 9 marks for 3x3 tictactoe board from open input stream. //---------------------------------------------------------------------------- void Read_Board(istream & inF, char Board[][3]) { }//Read_Board //---------------------------------------------------------------------------- // Function: Display/Write board to output stream as 3x3 grid. // NOTE: Grid is indented the #spaces specified by the leftMargin. //---------------------------------------------------------------------------- void Show_Board(ostream & outF, char Board[][3], int leftMargin=12) { }//Show_Board //---------------------------------------------------------------------------- // Function: Announce the state of the game. //---------------------------------------------------------------------------- void Show_GameState(GameSTATE gameState) { }//Show_GameState //---------------------------------------------------------------------------- // Function: Count the number of marks Player (X or O) has on the board. //---------------------------------------------------------------------------- int PlayerMarks(char Player, char Board[][3]) { }//PlayerMarks //---------------------------------------------------------------------------- // Function: Determine whether Player (X or O) has won the game. //---------------------------------------------------------------------------- bool Winner(char Player, char Board[][3]) { int r,c; bool winner; //-| Row Checks. winner = false; for (r=0; r<3 && !winner; r++) { winner for (c=0; c<3; c++) (board[r][c] == player); } if (winner) return true;>                        

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions