CSE 241/505 Homework # 4 solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

Rate this product

In this homework, you will re-write your game of Connect Four program in C++ using dynamic
memory techniques. You will not use any vectors or constant sized arrays.
Your main class for this homework will be named ConnectFour. This class will have a private
inner class named Cell to represent a Connect Four cell. The class Cell will hold the position of
the cell (A, B, C, etc) and the row number (1, 2, 3, etc). This class will also include all necessary
setters/getters, constructors etc. Remember a cell can be empty, user (user1, user2) or computer. You
will overload the following operators for the class cell.
• Operator== to compare two cells
• Pre and post increment/decrement operators for cell. The ++ operator changes the cell state
from empty to user1, from user1 to user2, from user2 to computer, from computer back to
empty.
• Stream insertion and extraction operators for cell.
Next, write a class named ConnectFour to represent and play the game. The class
ConnectFour will hold a Cell ** gameBoard data member to represent the game board as
a two dimensional dynamic array.
The class ConnectFour will also have the following features and functions
• There is no limit for the board. Your game will resize according to the parameter for the
constructor.
• There should be at least 3 constructors.
o The no parameter constructor creates a 5×5 game
o Another contructor takes number of rows and columns as parameters
o Another constructor takes a text file as a parameter. This text file will contain the
board shape marked with * characters. For example, the following is a board
configuration: it has 7 rows and 17 columns. Some of the columns are shorter than the
others.
***
*****
*******
*********
***********
**************
*****************
• The class will have functions to read and write from files. You will decide on the file format.
• The class will have functions to print the current configuration of the board to the screen.
• The class will have two functions named play that plays the game for a single time step. First
function does not take a parameter and it plays the computer. The second function takes a cell
position and it plays the user.
• The class should have a function that returns if the game ended.
• The class should have a function named playGame. This function plays the game by asking
the user the board file name first then asks the user to play and the computer plays, etc.
• The class will overload operator== and operator !=
• Any other functions (public or private) needed.
Write your main function to test both classes. Make at least 5 objects of class ConnectFour and
play the games at the same time.
You will use all the object oriented techniques that we learned in the class including const,
static, inline keywords.
Notes:
• Do not use any functions from the standard C library (like printf)
• Read the chapter about file input output for reading and writing text files using streams.
• Do not use anything that we did not learn in the lectures.
• Do not forget to indent your code and provide comments.
• Check the validity of the user input.
• Test your programs very carefully several different runs. Submit at least two saved files
with your HW.
• Submit at least 3 sample board configuration files.
• You should submit your work to the moodle page.