Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create a c + + program for the following requirements Make sure to name your project with your last name, first name initial, and

create a c++ program for the following requirements
Make sure to name your project with your last name, first name initial, and ".pgmX" where X is the program number. For
example, a student named Ben Afflack would use AfflackB_pgm1 for his program 1 solution.
In this assignment, you will write a program to implement a popular game of Tic-Tac-Toe. Two
people can take turns to play the game by providing input consisting of position on the Tic-Tac-Toe
board for the next " x " or "O" mark.
You will implement the game using a 2-D array representing rows and columns. The game grid will
include heading over columns and numbers for the rows.
The initial grid for the game will be empty and look like the picture below. Notice the nice lines used
to display the tic-tac-toe grid? The extended ASCII characters used to display this grid can be located
at
http://asciitable.com website. For example, + character is used for the crossed lines and has a
decimal value of 197. This grid will be initially created by reading the provided data file, prg 7-
input.txt, and converting the given decimal values into char data type (hint: type casting) to initialize
the 2-D char array representing the grid. The 2-D array should have 6 rows and 13 columns. Blank characters, i.e., spaces, are shown in a light tan color. The green cells will start as a space but
will be replaced by x and O as the game progresses.
The user will enter A1 or any combination of the column letter and row number. Allow lower or upper
case letters as valid column input. Below is an example of prompting the user for their first move. X
always moves first. Use a bool variable to track whether x or O has the next turn.
Utilize data validation to be sure the user does not provide an invalid value, for example, D7. Also,
make sure to catch it when the user tries to place their X or O over an already occupied cell of the
grid. Below are examples of this error handling.
Your move. Enter column , or l follwed by row , or 3
The tic-tac-toe grid is printed to the console windows using the extended ASCII chars shown in the table below.You are required to write the following functions. All of these functions will be called by main().
readInitialGrid function will read the Pgm7_Input.txt file to initialize the game grid 2-D
array. This function will be void and receive the game grid 2-D array and ifstream variable as
a parameter.
initiatlizeGrid function will initialize only the game cells where Xs and Os are placed after a
game is played. This function will be void and receive the game grid 2-D array as a parameter.
displayGrid function will print each cell of the 2-D grid to the console window. This function
will be void and receive the game grid 2-D array as a parameter.
isWin function will determine if Xs or Os have won the game. It will return true if there is a
winner and false otherwise. It will receive the game grid 2-D array and count of moves as
parameters.
Be sure to declare and use constants for ' x,'' O ', and space characters.
Be sure to declare constants ROWS and COLS, and use them in the declaration of the 2-D
array.
Be sure to prototype all of your functions.
Be sure to verify that the data file was opened correctly and closed when you are done reading
the data. The program should do nothing else, if the data file cannot be opened correctly.
Be sure to use switch statements to translate user input of columns and rows to the grid
indexes.
Be sure to use a bool variable to keep track of X/O turn. Alternate the turns. Xs always start.
Be sure to validate the user's input when asking if they want to play again. Hint: Use do-while
loop.
Be sure to validate the user's input when asking for the next move. You may assume that the
user will enter a column letter followed by an integer. Hint: Use the do-while loop.
Be sure to have documentation headers on each function.
You have been given a suggested design in the structure chart, which shows the functions that should be part of
the program. First, create a "stub" program for your solution. A stub program should contain function
prototypes, function calls, and function headers - all with any needed parameters (arguments). Function bodies
should be empty with correct return value and braces. The main function should declare variables needed, and
should only contain function calls. All of this should compile.R

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

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions

Question

Prepare a constructive performance appraisal.

Answered: 1 week ago

Question

List the advantages of correct report formatting.

Answered: 1 week ago