Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write all questions in the one promgram Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players,

write all questions in the one promgram

Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 33 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game. Q1) Write a C function that allows the user to initialize a Tic-Tac-Toe board. The board is a 2D array of size 3x3. The function will set an id for each cell of the board starting from 1 and stop at 9. The function prototype is void InitializeBoard ( int m, int n , char board[][n]) Here is a sample output showing the board after initializing it using the function

image text in transcribed

void InitializeBoard ( int m, int n , char board[][n]) { int c = 1 ; for ( int i = 0 ; i for ( int j= 0 ; j

Q2) Write a C function that allows the user to print a Tic-Tac-Toe board. The function prototype is void PrintBoard ( int m, int n, char board[][n]) .

image text in transcribed

Q3) Write a C function that allows the user to create a Tic-Tac-Toe board. In this case, the board is a 2D array of size 3x3, The function allows the user to create a board and set some X or O on the board at any cell. The function prototype is void CreateBoard (i nt m, int n, char board[][n]) . Here is a sample output when we execute the function CreateBoard

image text in transcribed

If the user typed any invalid input like cell number 21 or rather than entering X or O the user typed C the function should ignore his input and ask him to enter a valid input. Here is an example of this behavior

image text in transcribed

Q4) Write a C function that allows the user to check if a given Tic-Tac-Toe board is a valid board or an invalid board. The board is valid if it is an empty board or if the difference between the total number of X and the total number of O symbols on the board is 0 or 1. The function prototype is int IsValidBoard ( int m, int n, char board[][n]) .

image text in transcribed

Q5) Write a C function that allows the user to find if any next move or next play for any player X or O who has the turn to play is winning move. The function will print the cell number or ID that if the player places an X or O in it he/she will win the game. If there is more than one cell where the player could place his symbol in and win the game the function should print all the winning cells for that player. The function prototype is void ListWinningCells ( int m, int n, char board[][n])

image text in transcribed

Q6) Write a main function that displays a menu for the user and asks him to select which function he/she wants to test. Here is a sample output of the main function

image text in transcribed

1 2 3 4. 5 6 7 8 9 Program finished with exit code o 1 2 3 4. 5 6 7 8 9 Program finished with exit code 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

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions