Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please implement a basic version of Tic Tac Toe: 1.using c++ Function main and function headers are provided. Please implement the functions and do not

Please implement a basic version of Tic Tac Toe: 1.using c++ Function main and function headers are provided. Please implement the functions and do not change the main. 2. Our program must produce identical output: ASMT02_PA_Run1.txt and ASMT02_PA_Run2.txt

#include using namespace std;

bool isWon(char, char[][3]); bool isDraw(char[][3]); void displayBoard(char[][3]); void makeAMove(char[][3], char);

int main() { // // PLEASE DO NOT CHANGE function main // char board[3][3] = { { ' ', ' ', ' ' },{ ' ', ' ', ' ' },{ ' ', ' ', ' ' } }; displayBoard(board);

while (true) { // The first player makes a move makeAMove(board, 'X'); displayBoard(board); if (isWon('X', board)) { cout << "X player won" << endl; exit(0); } else if (isDraw(board)) { cout << "No winner" << endl; exit(0); }

// The second player makes a move makeAMove(board, 'O'); displayBoard(board);

if (isWon('O', board)) { cout << "O player won" << endl; exit(0); } else if (isDraw(board)) { cout << "No winner" << endl; exit(0); } }

return 0; }

out put should be

------------- | | | | ------------- | | | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player X : 0 Enter a column (0, 1, 2) for player X: 0

------------- | X | | | ------------- | | | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player O : 0 Enter a column (0, 1, 2) for player O: 0 This cell is already occupied. Try a different cell Enter a row (0, 1, 2) for player O : 0 Enter a column (0, 1, 2) for player O: 1

------------- | X | O | | ------------- | | | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player X : 1 Enter a column (0, 1, 2) for player X: 1

------------- | X | O | | ------------- | | X | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player O : 2 Enter a column (0, 1, 2) for player O: 2

------------- | X | O | | ------------- | | X | | ------------- | | | O | ------------- Enter a row (0, 1, 2) for player X : 1 Enter a column (0, 1, 2) for player X: 0

------------- | X | O | | ------------- | X | X | | ------------- | | | O | ------------- Enter a row (0, 1, 2) for player O : 2 Enter a column (0, 1, 2) for player O: 0

------------- | X | O | | ------------- | X | X | | ------------- | O | | O | ------------- Enter a row (0, 1, 2) for player X : 1 Enter a column (0, 1, 2) for player X: 2

------------- | X | O | | ------------- | X | X | X | ------------- | O | | O | ------------- X player won

------------- | | | | ------------- | | | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player X : 1 Enter a column (0, 1, 2) for player X: 1

------------- | | | | ------------- | | X | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player O : 0 Enter a column (0, 1, 2) for player O: 2

------------- | | | O | ------------- | | X | | ------------- | | | | ------------- Enter a row (0, 1, 2) for player X : 2 Enter a column (0, 1, 2) for player X: 2

------------- | | | O | ------------- | | X | | ------------- | | | X | ------------- Enter a row (0, 1, 2) for player O : 0 Enter a column (0, 1, 2) for player O: 0

------------- | O | | O | ------------- | | X | | ------------- | | | X | ------------- Enter a row (0, 1, 2) for player X : 2 Enter a column (0, 1, 2) for player X: 0

------------- | O | | O | ------------- | | X | | ------------- | X | | X | ------------- Enter a row (0, 1, 2) for player O : 2 Enter a column (0, 1, 2) for player O: 1

------------- | O | | O | ------------- | | X | | ------------- | X | O | X | ------------- Enter a row (0, 1, 2) for player X : 1 Enter a column (0, 1, 2) for player X: 0

------------- | O | | O | ------------- | X | X | | ------------- | X | O | X | ------------- Enter a row (0, 1, 2) for player O : 1 Enter a column (0, 1, 2) for player O: 2

------------- | O | | O | ------------- | X | X | O | ------------- | X | O | X | ------------- Enter a row (0, 1, 2) for player X : 0 Enter a column (0, 1, 2) for player X: 1

------------- | O | X | O | ------------- | X | X | O | ------------- | X | O | X | ------------- No winner

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions