Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that plays a tic-tac-toe game with the user. Define a class TicTacToe with the necessary data and functions to play the

Write a C++ program that plays a tic-tac-toe game with the user.

Define a class TicTacToe with the necessary data and functions to play the game. Use a 2-D char array with three rows and three columns as the game board. The class should also have the following functions:

A constructor to initialize the board. I suggest either asterisk ('*') or characters '1' through '9'.

A function to fill in the board with either an 'X' or 'O' given row and column number (1-3) or position number (1-9), for example.

A function to play the computer's turn. This function will determine the row and column number to be filled in. You can use a simple algorithm such as look for the first space available, or random number generation. Complex AI algorithms will only be accepted with an in-person explanation of its behavior.

A function to play the user's turn. This function should ask the user for row (1-3) and column (1-3), or position (1-9) number. Note that position number is easier for the user to play but will have to be broken down into row and column number by your program.

A function to verify if there is a win. This can be broken down by calling 3 separate private functions that can verify column win, row win or diagonal win. If there is no winner, let the user know there is a tie.

The main function should create a TicTacToe object and call the appropriate member functions to implement the logic of the game. For example, I expect you to have a loop that allows the user and computer to take turns until a win is detected.

Note that all member functions that you need to call in main through the TicTacToe object should be public, but functions needed only inside your class implementation (called only by other functions in your class) should be private.

You can decide who will have 'X' or 'O'.

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

To find integral of sin(logx) .

Answered: 1 week ago

Question

KEY QUESTION Refer to the table in question

Answered: 1 week ago