Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create tictactoe.cpp with the functions in the header file. tictactoe.h #pragma once class tictactoe { private: char moves[3][3]; // it is your 3 by 3

Create tictactoe.cpp with the functions in the header file.

tictactoe.h

#pragma once class tictactoe { private: char moves[3][3]; // it is your 3 by 3 board bool xturn; // shows whose turn it is (True-> X ; False -> O)

public: //should initialize whose turn it is and the moves array with empty spaces tictactoe();

//should place an X or O, based on whose turn it is, at location x,y in the moves array // make sure the move is correct meaning it is in the board range and also the place is not already occupied // update the turn : If it was X turn, now it is O turn bool PlaceMove(int x, int y);

/*draws the board using the moves 2d array. At first it should look like this 0 1 2 0 | | ---------- - 1 | | ---------- - 2 | | */ void DrawBoard();

//should return true if there are 3 X's or 3 O's in a row or in diagonal ; also return true if the board is full bool GameOver();

//should return X or O ; the winner is usually the one who made the last move char Winner();

};

Source.cpp

/* This program is the tictactoe game. Output should look like this:

0 1 2 0 | | ----------- 1 | | ----------- 2 | | Row: 1 Col: 1

0 1 2 0 | | ----------- 1 | X | ----------- 2 | | Row: 1 Col: 2

0 1 2 0 | | ----------- 1 | X | O ----------- 2 | | */

#include #include "tictactoe.h"

using namespace std;

int main() { tictactoe board; int col, row; do { board.DrawBoard(); cout << "Row: "; cin >> row; cout << "Col: "; cin >> col;

if (!board.PlaceMove(row, col)) cout << "Invalid Move" << endl; } while (!board.GameOver());

board.DrawBoard(); cout << board.Winner() << " wins!" << endl;

return 0; }

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

More Books

Students also viewed these Databases questions