Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ tic tac toe help The main() and function headers are provided. Please implement the functions, can add new ones, and do not change the

C++ tic tac toe help

The main() and function headers are provided. Please implement the functions, can add new ones, and do not change the main().

2. Your program must produce identical output: Part1_Run1.txt and Part1_Run2.txt

-Code

#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 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;

}

- Output needed

------------- | | | | ------------- | | | | ------------- | | | | ------------- 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 Press any key to continue . . .

- Output 2

------------- | | | | ------------- | | | | ------------- | | | | ------------- 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 Press any key to continue . . .

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

What is the highest outlier from the in-person transactions?

Answered: 1 week ago

Question

What is the median transaction for in-person transactions?

Answered: 1 week ago

Question

What is the maximum for SALE_PRICE?

Answered: 1 week ago