Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Learning Objectives: The intent of this programing project is to allow you the opportunity to demonstrate your ability to solve problems using procedural C++ programming.

Learning Objectives:

The intent of this programing project is to allow you the opportunity to demonstrate your ability to solve problems using procedural C++ programming. This project will focus on using loops, functions, random numbers, and the correct use of global variables in the implementation of the Tic-Tac-Toe game.

Program Description: In this design project, you will implement a Tic-Tac-Toe game between a user and the computer. You may make the following assumptions: The user is always the first player and the computer is the second player. The user gets the marker X and the computer gets the marker O.

Optional (extra credit):

Option 1 [5 points]: Ask the user to flip a coin to determine who (either the user or the computer) should play first

. Option 2 [5 points]: Ask the user (or the first player) to choose their own marker, between X and O.

Option 3 [5 points]: Create separate .h and .cpp files for each function.

Program Requirements:

Create a function to draw the tic-tac-toe board

Tic-Tac-Toe is a game that two parties play taking turns to mark a space (with X and O) in a 3x3 board. The player wins who succeeds to put three marks on a line (horizontal, vertical, or diagonal). As the first step to implementing the Tic-Tac-Toe game, you are required to create a function that draws the Tic-Tac-Toe board. This function will get called repeatedly until either all the nine spaces (or slots) on the board have been played (Draw) or a player wins.

Initially, the nine spaces will have numbers associated with individual slots, as shown in the screen shot below. Then, after each play, a users or a computers chosen a slots will show either X or O to designate the choice instead of the slot number. You will create a function to draw the board 1) initially with no choices made and 2) after each choice is made either by the player or by the computer.

Create a function to check the input is within the valid range

As a Tic-Tac-Toe board has only 9 slots, if the input position is less than 1 or greater than 9 then an error message should display (for example, Invalid input: the position indicator has to be in the range of 1 to 9, as shown in the screen shot below). This error checking should be performed every time the user enters a number.

Create a function to check the designated space is available

After passing the input validation test, the program has to check if the designated space is available. Create a function to examine whether the selected spot is available. Use the fact that the occupied spots (which were previously played) have either X or O character instead of the spot number (1 through 9). When the selected spot is available, mark it with X or O; if not, either ask the user to enter another number (as shown in the example below) or pick another random spot (when it is the computers turn to play).

In the example below, the space 6 that the user designates is already taken. The character O in the space means that the computer placed the marker there. Therefore, the program asks the user to enter another position, and this time the user enters 3, whose corresponding space is available.

Create a function to check if we have a winner (and the program should end)

Whenever a new position is marked, the program should check whether there is a winner. If there is a winner, the winner is displayed and the program is terminated. If not, it will continue to play. In the example below, there are unplayed slots left (4, 5, 7, 8) but there are three Xs on the top row. Therefore the user is a winner, which is displayed and the program is terminated.

Create a main() program

main() will play the complete Tic-Tac-Toe game including all the fore mentioned functions. Other function may be added as needed but are not required.

NOTE: You cannot use arrays for this project.

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions