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

  Create a project named animated with a form

Create a project named GuessANumber with a Form that contains a guessing game with five RadioButtons numbered 1 through 5. Randomly choose one of the RadioButtons as the winning button.

  Create new windows forms application named averagecalculator

Clearing the result. Write event handlers for the TextBoxes'TextChanged events. Write code to clear resultLabel after the user enters new input into any of the TextBoxes.

  Find out a web site which describes the use of a selection

find a web site that explains the use of a selection structure or an iteration structure in programming. provide the

  Write error message and repeat input until a answer is found

Give the user specific instructions for what their answer should be (i.e. Y or N). If their answer is anything other than one of the specified choices, write an error message and repeat the input until a desired answer is found.

  Weekly demand for motorola cell phones at a retail store is

weekly demand for motorola cell phones at a retail store is normally distributed with a mean of 300 and a standard

  Prepare a computer program to simulate the traffic

Write a computer program to simulate the traffic on a 2D plane under different traffic light control schemes.

  Demonstrates a basic knowledge of the programming language

Write a 2-3 page report over your programming languages topic. This may be either a paper or 2 pages of code that demonstrates a basic knowledge of the programming language.

  List various bindings to determine the semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

  Program for sentinel address of all zeros and nickname

Explain class called address_t with members for four integers and must read list up to 100 addresses and nicknames terminated by sentinel address of all zeros and nickname.

  You have in your program an arraylist which contains

you have in your program an arraylist that contains employee salaries double type in arbitrary order. you need to

  Javascript function to validate a text-field on a form

Write a JavaScript function to validate a text-field on a form that is to hold an email address.

  Implement floyd warshall algorithm in c language

Implement floyd warshall algorithm in c language.add comments for explanation

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