Question: Write a C++ program, tictac.cpp , that repeatedly reads in tic-tac-toe boards and for each one indicates if there is a winner and who won.

Write a C++ program, tictac.cpp, that repeatedly reads in tic-tac-toe boards and for each one indicates if there is a winner and who won.

The board will be read in as 3x3 array of characters (x, o or . for a blank spot).

You are required to write the following functions to help solve the problem:

// input prompts the user for a board and inputs it

// into the given array

void input (char board [3][3]);

// print prints the board in nice format

void print (char board [3][3]);

// win returns true if the given player has won on the

// given board, else it returns false

bool win (char board [3][3], char player);

You are required to use nested loops to write the functions input and print.

The back of this page shows a sample run of the program (input in bold). Your output should look at least as nice as that shown. You may assume that the board will be legal and there will be at most one winner.

Enter your board as characters (x, o or .):

o.x

..o

.x.

The board is:

o | | x

-----------

| | o

-----------

| x |

No winner!

Would you like to do another (y or n)? y

Enter your board as characters (x, o or .):

oxo

ox.

.xo

The board is:

o | x | o

-----------

o | x |

-----------

| x | o

X wins!

Would you like to do another (y or n)? y

Enter your board as characters (x, o or .):

xoo

xox

ox.

The board is:

x | o | o

-----------

x | o | x

-----------

o | x |

O wins!

Would you like to do another (y or n)? n

Thanks for playing!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!