Many computer games, be they strategy games, simulation games, or first-person conflict games, use a two-dimensional board. Programs that deal with such positional games need a way of representing objects in a two-dimensional space. A natural way to do this is with a two-dimensional array, where we use two indices, say i and j, to refer to the cells in the array. The first index usually refers to a row number and the second to a column number. Given such an array we can then maintain two-dimensional game boards, as well as perform other kinds of computations involving data that is stored in rows and columns.

Arrays in C++ are one-dimensional; we use a single index to access each cell of an array. Nevertheless, there is a way we can define two-dimensional arrays in C++we can create a two-dimensional array as an array of arrays. That is, we can define a two-dimensional array to be an array with each of its cells being another array. Such a two-dimensional array is sometimes also called a matrix. In C++, we declare a two-dimensional array as follows:

int M[8][10]; // matrix with 8 rows and 10 columns


Create a Visual Studio Project TicTacToe-2D.sln for the Tic-Tac-Toe game described (p.114 textbook). Utilize the support files and add a file tictactoe.cpp, for your source code.

# File Name
1 TicTacToe.cpp-TTT1.html
2 TicTacToe.cpp-TTT2.html

Once you have completed the source code, and compiled. Execute the code and it should produce the following results.

X|O|X X wins

Problem 1

a) In the Tic-Tac-Toe example, we used 1 for player X and 1 for player O. Modify the tictactoe.cpp programs counting trick to decide the winner if we had used 1 for player X and 4 for player O instead.

b) Could we use any combination of values a and b for the two players? Explain.

Problem 2

Suppose you are designing a multi-player game that has n 1000 players, numbered 1 to n, interacting in an enchanted forest. The winner of this game is the first player who can meet all the other players at least once (ties are allowed). Assuming that there is a function meet(i,j), which is called each time a player i meets a player j (with i j), describe a way to keep track of the pairs of meeting players and who is the winner.

Problem 3

Create the file threedimensional.cpp, and write a C++ function addArray(arrayone, arraytwo), that takes two three-dimensional integer arrays and adds them componentwise, then prints the results. The integer arrays should be allocated in the main() function and filled using a random number generator that produces integers between 0 and 100.

Problem 4

Create the file matrixmath.cpp. Write a C++ class MatrixMath. The class should have a default constructor, and destructor. Implement member functions that can add and multiply arbitrary twodimensional arrays of integers. Do this by overloading the addition (+) and multiplication (*) operators. The MatrixMath class should be included in the matrixmath.cpp. Implement a main() function that generates random 2 dimensional arrays and call the overloaded operators for testing. Print the input and output results to demonstrate your implementation is correct.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.