Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ You have been given part of the code (in main() and some function declarations) but will need to add code in several functions

Using C++

You have been given part of the code (in main() and some function declarations) but will need to add code in several functions to implement the game of Tic-Tac-Toe. The starting point for this lab exercise can be found in section 4.31 of Zybooks.

Since we have not yet discussed parameter passing in C++ when using functions, just for this program we will use global variables, even though using global variables in your programs is strongly discouraged and usually will lead to point deductions. The game starts by player 'X' selecting a move position. Players alternate on every move, until someone wins (with three in a row) or the board is filled and the game is a draw. Running the program should look like the following, where user input is shown below in bold:

Welcome to the TicTacToe game!

Take turns entering the position (1..9)

into which your piece will be placed.

Enter '0' (zero) to exit.

-------

| | | | 1 2 3

-------

| | | | 4 5 6

-------

| | | | 7 8 9

-------

1. Enter the move (1..9) for X: 1

-------

|X| | | 1 2 3

-------

| | | | 4 5 6

-------

| | | | 7 8 9

-------

2. Enter the move (1..9) for O: 3

-------

|X| |O| 1 2 3

-------

| | | | 4 5 6

-------

| | | | 7 8 9

-------

3. Enter the move (1..9) for X: 4

-------

|X| |O| 1 2 3

-------

|X| | | 4 5 6

-------

| | | | 7 8 9

-------

4. Enter the move (1..9) for O:

-------

|X| |O| 1 2 3

-------

|X| | | 4 5 6

-------

|O| | | 7 8 9

-------

5. Enter the move (1..9) for X: 5

-------

|X| |O| 1 2 3

-------

|X|X| | 4 5 6

-------

|O| | | 7 8 9

-------

6. Enter the move (1..9) for O: 6

-------

|X| |O| 1 2 3

-------

|X|X|O| 4 5 6

-------

|O| | | 7 8 9

-------

7. Enter the move (1..9) for X: 9

-------

|X| |O| 1 2 3

-------

|X|X|O| 4 5 6

-------

|O| |X| 7 8 9

-------

Congratulations player X. You WON!

Exiting program...

Do not edit the code in main(). The code in main() calls various functions. You must complete the code in these functions so that the game works properly.

Step 1: (1 Point)

Complete the function displayBoard(). It should use the board variables to display the board.

Step 2: (1 Point)

Complete the function makeMove() which allows the user to make a move. It should prompt for user input, read in the user input number, and change to appropriate board variable.

Step 3: (1 Extra credit Point)

Complete the checkBoard() function that checks for a win after every turn. A win can be three of the same kind on any row, column, or diagonal.

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions