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 (3 by 3) tic-tac-toe board.
You have been given code for the main, wStep 2: (3 points) Write the function moveToSquare(char square, char player) which allows the user to place choose a spot on
DEFAULT TEMPLATE:
// Lab3.cpp
// for CS 141 lab 3
#include
using namespace std;
char p1,p2,p3,p4,p5,p6,p7,p8,p9;
// 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:
//-------
//|a|b|c|
//-------
//|d|e|f|
//-------
//|g|h|i|
//-------
//(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:
//-------
//|a|X|c|
//-------
//|d|e|f|
//-------
//|g|h|i|
//-------
void moveToSquare(char 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
p1='a',p2='b',p3='c',p4='d',p5='e',p6='f',p7='g',p8='h',p9='i';
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'){
moveToSquare(square, 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 1;
}// end main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!