Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

here is the code: #include <iostream> using namespace std; void printBoard(const

ID: 3753179 • Letter: H

Question

here is the code:

#include <iostream>
using namespace std;

void printBoard(const char b[][3], const int size);
void placeMove(char b[][3], int row, int col, char player);

int main() {

   /* Type your code here. */

   return 0;
}

5.14 LAB: 2D arrays For this lab we will be working with a 2D array of characters. A standard tic-tac-toe game can be viewed as a 3x3 2D array. First, create your 3x3 array, and fill it with spaces (remember, by default any array is full of garbage!). To see your board, create a printBoard function to print out the array with pipes (T) before and after each element of the array. (3 pts) Ex: Next, we are going to implement a (very) simple gameplay function: placeMove (1pt). This function will not do any error checking, but simply assume that good row, column, and player character data are passed to it. Your main should prompt the user for a row, column, and character. After this, you should call your placeMove function, followed by a call to printBoard. (2pts) Ex: Enter row: 1 Enter column: 2 Enter player character x or o) o For fun download your submission and modify in Code Blocks Modify to prompt users for placeMove in a loopmake it a real game!

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#include <iostream>
using namespace std;
void printBoard(const char b[][3], const int size);
void placeMove(char b[][3], int row, int col, char player);
int main() {
int row, col;
char player;
const int size = 3;
char b[size][size];
//initialize
for(int r = 0; r < size; r++){
for(int c =0; c < size; c++){
b[r][c] = ' ';
}
}
printBoard(b, size);
cout << "Enter row: ";
cin >> row;
cout << "Enter column: ";
cin >> col;
cout << "Enter player character (X or O): ";
cin >> player;
cout << endl;
placeMove(b, row, col, player);
printBoard(b, size);
}

void printBoard(const char b[][3], const int size)
{
for(int r = 0; r < size; r++){
cout << "|";
for(int c =0; c < size; c++){
cout << b[r][c] << "|";
}
cout << endl;
}
cout << endl;
}
void placeMove(char b[][3], int row, int col, char player){
b[row][col] = player;
}

output
-----
| | | |
| | | |
| | | |
Enter row: 1
Enter column: 2
Enter player character (X or O): O
| | | |
| | |O|
| | | |