Write program that will allow two users to play tic-tac-toe

Assignment Help Programming Languages
Reference no: EM131344123

Program: Tic Tac Toe

Write a program that will allow two users to play tic-tac-toe. The program should ask for moves alternatively from player X and player O. The display should be board-like:

1 2 3
4 5 6
7 8 9

The players enter their moves by entering a number corresponding to the place to be marked. After each move, the program displays the changed board. After several moves the board may look like this:

X X O
4 5 6
O 8 9

You will write a class called Game. The class will have as a data member

1) an array of size 9, type char, called board

It should also have the following member functions:

A constructor that takes no parameters but initializes the game board to 1 through 9

A function that displays the game board. Remember that after ever 3 elements, it should print a new line so that the board displays as shown above. The board needs to be displayed before every move.

A function called play that will take in at least one parameter of either X or O, depending on which player's turn it is. Additionally, you could add the parameter of the move that player entered (or you could ask for the input within this function). The main purpose of this function is to modify the game board. It must check that only 1 through 9 has been entered, that the space the user has chosen is not yet taken, and then change the game board accordingly. It is up to you to give the player another turn or to pass to the next player if they have chosen an incorrect space.

A function called checkWin, which checks to see if there are any winners. In tic-tac-toe, you win with all of the same marker across, down, or diagonal. You may want this to be a Boolean function.

If you would like to add more data members or functions, you may do so, but the 5 above are required.

Reference no: EM131344123

Questions Cloud

Examine ways that cultural expressions influence daily life : Examine the ways that cultural expressions influence your daily life. You are welcome to use images in this Assignment, however, the written content needs to be at least 750 words
Concept of discount rate-weighted average cost of capital : What is the general intention behind the Truth-in-Lending law? List three requirements under this regulation. Explain the concept of a discount rate and the weighted average cost of capital.  Provide a detailed overview of the top-down, three-step ap..
Create a literature review incorporating each of references : Create a literature review, incorporating each of your references (minimum of five), tying them to each other and to the thesis of your project in a single narrative. You should cite each source in the body of your literature review and in a refer..
Determine the distance x locating the weight a : The self-regulating floodgate ABC, pinned at B, is pressed against the lip of the spillway at C by the action of the 3645-lb weight A. If the gate is to open when the water level reaches a height h = 6 ft, determine the distance x locating the wei..
Write program that will allow two users to play tic-tac-toe : BIS 320- Write a program that will allow two users to play tic-tac-toe. The program should ask for moves alternatively from player X and player O.
Develop a plan to reduce driving under the influence : For your selected age group, develop a plan to reduce driving under the influence. The plan could include (but not be limited to) educational, legislative, and community support; and social advertising. Present at least three action points in your..
Find the smallest wind load q that would cause the structure : Compute the magnitudes of the reactions at A and B if the wind load on the billboard is q = 120 lb/ft.
Theories of lamers and kubler-ross : Imagine that you are a hospice volunteer and are helping late adult, terminally ill patients and their families. Use the theories of Lamers and Kubler-Ross to help you and the families better understand and deal with their circumstances
What are the desirable attributes : What are the desirable attributes of a successful portfolio manager? What was the problem with the early performance measures and how have the modern composite portfolio performance measures overcome this problem

Reviews

Write a Review

Programming Languages Questions & Answers

  Program that computes the average and standard deviation

Write a program that computes the average and standard deviation of a set of double values read from a file.

  Find the minimum initiation interval and a uniform schedule

Using the machine model, find the minimum initiation interval and a uniform schedule for the iterations, for the given loop:

  How to complete input assertion and output assertion

Complete input assertion and output assertion which will guarantee that student always ends game passing class. Add assertions and invariants which can help reason about claim.

  Write a function that returns a list with all the numbers

Write a function that returns a list with all the numbers from 1 to n (inclusive) that are a multiple of mm. The function should have as parameters the numbers n and m , and return a list with the qualifying numbers.

  Write function which takes a string as the argument

Some examples are: "1234321", "C", "ABCBA". Write down a function which takes a string as the argument and returns 1 if string is palindrome and 0 otherwise.

  Program that creates a series of random 2d objects

Create a program (OpenGL, or DirectX) that creates a series of random 2D objects, (or 3D objects that only move in 2D), about 25 is probably good but you may need more or less and has them move around on the screen, they should wrap around the edg..

  In the context of information processing computer security

1.in the context of information processing computer security and trusted systems explain what is meant by the following

  Is this an example of head or tail recursion

Referring to the code in Part 1, use the substitution model to illustrate what the result of calling (add1-iter '(1 2 3)) will be. Why is the list reversed ?

  Create the program uses two arrays to hold employee names

Create the program which uses two arrays: one to hold employee names and one to hold employee salaries (standard US currency, two decimal points). The program must prompt user to enter employee names.

  Create an xml file with markup tags and some sample data

Create an XML file with markup tags and some sample data to represent a list of invoices

  What is the value displayed on the led

In the Data1: window, right click on num1, then left click on Show Location.  The value of the initialized variables should appear in the Memory window. Cut and paste the Memory window. What is the value displayed on the LEDs after you single step th..

  Create application which simulates functionality of gas pump

Create application which simulates functionality of gas pump. The user enters number of gallons to buy and clicks desired grade.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd