Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Objective: 

Design a program that uses two-dimensional arrays, classes and objects

Assignment:

Write a program that plays a tic-tac-toe game with the user.

Define a class TicTacToe with the necessary data and functions to play the game. Use a 2-D char array with three rows and three columns as the game board. The class should also have the following functions:

  • A constructor to initialize the board. I suggest either asterisk ('*')  or characters '1' through '9'.
  • A function to play the user's turn, fill in the board with either an 'X' or 'O' given row and column number (1-3) 
  • A function to play the computer's turn. This function will determine the row and column number to be filled in. You can use a simple algorithm such as look for the first space available, or random number generation. Complex AI algorithms will only be accepted with an explanation of its behavior via a zoom meeting.
  • A function to verify if there is a win. This can be broken down by calling 3 separate private functions that can verify column win, row win or diagonal win. If there is no winner, let the user know there is a tie.

The main function to test your class is given. 

Note that all member functions that you need to call in main through the TicTacToe object should be public, but functions needed only inside your class implementation (called only by other functions in your class) should be private.

You can decide who will have 'X' or 'O'.

Have fun!

Turn in:

  • TicTacToe.h (or .hpp) and TicTacToe.cpp with the implementation of your class.

 

TicTacToe_main.cpp:

 

/********************************************************

Description: Tic-Tac-Toe driver program
Author: Hellen Pacheco
Date: October, 2020

********************************************************/
#include "TicTacToe.h"
#include <iostream>

using namespace std;

enum gameStatusType { USER, COMPUTER, TIE, INPROGRESS };
// values of gameStatusType are USER=0, COMPUTER=1, TIE=2, INPROGRESS=3

int main()

{

      int row, col;
      int gameStatus;
      TicTacToe tttGame;  // instantiates a Tic-tac-toe object

      cout<<"Hello, welcome to the Tic-Tac-Toe game."<<endl;

     do
     {
            tttGame.printBoard();
            cout<<"Please enter row#: "<<endl;
            cin >> row;
            cout<<"Please enter col#: "<<endl;
            cin >> col;
            tttGame.userMove(row, col);
            tttGame.computerMove();
            gameStatus = tttGame.determineWinner();
            switch (gameStatus)
            {
                  case USER : cout << "You won!"; break;
                  case COMPUTER : cout << "Computer won!"; break;
                  case TIE: cout << "It is a tie!"; break;
                  case INPROGRESS: continue;
             }
      } while (gameStatus == INPROGRESS);
      return 0;
}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education