Please I need!! Its due in a couple of hours.

+1 Boosie Kubi · May 7, 2015

The program suppose to have .cpp file and .h file and im stuck. Ive been due since yesterday. The program is in the C++ book under the topic classes .

Problem:
(Tic-Tac-Toe) Write a program that allows two players to play the tic-tac-toe
game. Your program must contain the class ticTacToe to implement a
ticTacToe object. Include a 3-by-3 two-dimensional array, as a private
member variable, to create the board. If needed, include additional member
variables. Some of the operations on a ticTacToe object are printing the
current board, getting a move, checking if a move is valid, and determining the
winner after each move. Add additional operations as needed.

Post a Reply

Replies

Oldest  Newest  Rating
0 Christian Russell · May 7, 2015
What I would do is first create your board class:
class boardTicT{

}

Then give it a private array for the board:
class boardTicT{
     private:
          int boardArray[3][3]
}
Then do the following inside the class (functions are public, variables are private):

  1. create a constructor to set the values in the board to zero, using a set of for loops (Make 0 unused space, 1 player 1, and 2 player 2)

  2. create a public function that allows you to make a move (prompts the user for the row, then the column using cin). This function will change the value of the coordinates to whatever players turn it is.

  3. Create a global turns taken variable that increases by 1 when a turn is taken

  4. create a check current player function (hint: turnsTaken % 2)

  5. create a print board function: use a for loop that loops for each row, then inside that, make a for loop that loops for each column

  6. when a move is made (above function), be sure to use a while loop to check if it is a valid move (loop if a player has already moved there, and break the loop if the value is 0)


Hope this points you in the right direction!
  • 1

C++

107,009 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator