Question: CODE IN C + + . We will work on printing and allowing player moves on a ( 3 by 3 ) tic - tac
CODE IN C
We will work on printing and allowing player moves on a by tictactoe board.
You have been given code for the main, wStep : points Write the function moveToSquarechar square, char player which allows the user to place choose a spot on
DEFAULT TEMPLATE:
Labcpp
for CS lab
#include
using namespace std;
char ppppppppp;
Running display board should print out the board and the characters denoting each square.
Which would display either the letter for the square, or the X or O that has moved there.
Running the code after displayBoard function for the first time should be like:
abc
def
ghi
With no spaces before the board. The board is made of letters, vertical lines, and dashes: and
void displayBoard
Enter code here
This function allows a move to a specific square. For the initial move, if the square is b and player is X
after this method is called, the board would look like this:
aXc
def
ghi
void moveToSquarechar square, char player
Outputs "Congratulations you won!" if one of the players wins
all three squares in one row are the same,
all three squares in a column are the same,
or the three squares on a diagonal are the same
void checkForWin
int main
Initialize the board
papbpcpdpepfpgphpi;
char currentPlayer X;
char square ;
displayBoard;
cout "Player currentPlayer enter the square you would like to play in or q to quit: ;
cin square;
while square q
moveToSquaresquare currentPlayer;
Switch the current player
if currentPlayer X
currentPlayer O;
else
currentPlayer X;
displayBoard;
checkForWin;
cout "Player currentPlayer enter the square you would like to play in or q to quit: ;
cin square;
cout "Exiting program..." endl;
return ;
end main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
