Answered step by step
Verified Expert Solution
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 AfflackBpgm for his program solution.
In this assignment, you will write a program to implement a popular game of TicTacToe. Two
people can take turns to play the game by providing input consisting of position on the TicTacToe
board for the next x or O mark.
You will implement the game using a 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 tictactoe grid? The extended ASCII characters used to display this grid can be located
at
http:asciitablecom website. For example, character is used for the crossed lines and has a
decimal value of This grid will be initially created by reading the provided data file, prg
input.txt and converting the given decimal values into char data type hint: type casting to initialize
the D char array representing the grid. The D array should have rows and columns. Blank characters, ie 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 A 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, D 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
The tictactoe 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 PgmInput.txt file to initialize the game grid D
array. This function will be void and receive the game grid 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 D array as a parameter.
displayGrid function will print each cell of the D grid to the console window. This function
will be void and receive the game grid 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 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 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 XO 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 dowhile
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 dowhile 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started