View the step-by-step solution to:

Topics 8.1 Arrays Hold Multiple Values 8.2 Accessing Array Elements 8.3 Inputting and Displaying Array Contents 8.4 Array Initialization 8.5...

1)Write a modular program that allows two players to play a game of tic-tac-toe. Use a two-dimensional char array with 3 rows and 3 columns as the game board. Each element of the array should be initialized with an asterisk(*). The program should display the initial board configuration andthen start a loop that does the following:

*Allow player 1 to select a location on the board for an X by entering a row and column number. Then redisplay the board with an X replacing the * in the chosen location
*If there is no winner yet and the board is not yet full, allow player 2 to select a location on the board for an O by entering a row and column number. Then redisplay the board with an O replacing the * in the chosen location.

The Loop should continue until a player has won or a tie has occurred, then display a message indicating who won, or reporting that a tie has occurred.
*Player 1 wins when there are three Xs in a row, a column, or diagonal on the game board
*Player 2 wins when there are three Os in a row, a column, or diagonal on the game board
*A tie occurs when all locations on the board are full, but there is no winner.

Input Validation: Only allow legal moves to be entered. The row must be 1, 2, or 3. The column must be 1, 2, or 3. The(row,column) position entered must currently be empty(i.e., still have an asterisk in it).
Topics 8.1 Arrays Hold Multiple Values 8.2 Accessing Array Elements 8.3 Inputting and Displaying Array Contents 8.4 Array Initialization 8.5 Processing Array Contents 8.6 Using Parallel Arrays 8.7 The typedef Statement 8.8 Arrays as Function Arguments 8.9 Two-Dimensional Arrays 8.10 Arrays with Three or More Dimensions 8.11 Vectors 8.12 Arrays of Class Objects 8.1 Arrays Hold Multiple Values * Array : variable that can store multiple values of the same type *Values are stored in adjacent memory locations * Declared using [] operator const int ISIZE = 5; int tests[ISIZE]; Array Storage in Memory The definition int tests[ISIZE]; // ISIZE is 5 allocates the following memory Array Terminology In the definition int tests[ISIZE]; * int is the data type of the array elements * tests is the name of the array * ISIZE , in [ISIZE] , is the size declarator . It shows the number of elements in the array. *The size of an array is the number of bytes allocated for it (number of elements) * (bytes needed for each element) Array Terminology Examples Examples: Assumes int uses 4 bytes and double uses 8 bytes const int ISIZE = 5, DSIZE = 10; int tests[ISIZE]; // holds 5 ints, array // occupies 20 bytes double volumes[DSIZE]; // holds 10 doubles
Background image of page 01
// array is 80 bytes 8.2 Accessing Array Elements *Each array element has a subscript , used to access the element. *Subscripts start at 0 Accessing Array Elements Array elements (accessed by array name and subscript) can be used as regular variables tests[0] = 79; cout << tests[0]; cin >> tests[1]; tests[4] = tests[0] + tests[1]; cout << tests; // illegal due to // missing subscript 8.3 Inputting and Displaying Array Contents cout and cin can be used to display values from and store values into an array const int ISIZE = 5; int tests[ISIZE]; // Define 5-elt. array cout << "Enter first test score "; cin >> tests[0]; Array Subscripts *Array subscript can be an integer constant, integer variable, or integer expression *Examples: Subscript is cin >> tests[3]; int constant cout << tests[i]; int variable cout << tests[i+j]; int expression Inputting and Displaying All Array Elements To access each element of an array *Use a loop *Let the loop control variable be the array subscript * A different array element will be referenced each time through the loop for (i = 0; i < 5; i++) cout << tests[i] << endl; Getting Array Data from a File const int ISIZE = 5, sales[ISIZE]; ifstream dataFile;
Background image of page 02
Show entire document
Sign up to view the entire interaction

Top Answer

Dear Student Please find... View the full answer

8232736- Accounting.CPP

#include&lt;iostream.h&gt;
#include&lt;conio.h&gt;
void main()
{
char brd[3][3];
int i=0,j=0,x=0,y=0,pl1=1,pl2=1,pl_sc=1;
int turn=1;
for(i=1;i&lt;=3;i++)
{
for(j=1;j&lt;=3;j++)
{
brd[i][j]='*';
}...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online