Question
I wrote the C++ code to the problem below already, can you read and then answer these questions about how the code is implemented? Explain
Explain the object-oriented concepts used in the Tic Tac Toe application. (1 to 3 sentences per topic below please)
1 ) How are classes are used to model the game (encapsulation etc)? 2 ) How is inheritance and polymorphism used in the assignment? 3 ) How are smart pointers used to implement polymorphism? 4 ) explain the save game and get game strategy.
PLZ DO NOT WRITE CODE! I ALREADY HAVE IT, JUST NEED THE QUESTIONS ANSWERED. THANKS!
Tic Tac Toe application :
Understanding the Problem: The purpose of this assignment is to give students practice with class inheritance and polymorphism concepts. Students will write code to move some class functions from base class TicTacToe to newly derived classes TicTacToe3 and TicTacToe4. Modify main.cpp, prompt user to select between tic tac toe 3 or 4. Application Requirements Allow a user to play TicTacToe 3(connect 3 in a row to win) ,regular tic tac toe, in this case a vector of 9 pegs . Allow a user to play TicTacToe 4 (connect 4 in a row to win), a 4x4 board, in this case a vector of 16 pegs.
Implementation: I. Modify base TicTacToe and create TicTacToe3 and TicTacToe4 derived classes. InTicTacToe 1. Create a constructor with an int parameter named size. a. in the constructor use an initializer list to initialize the vector to 9 or 16 elements HINT(multiply 3 or 4 by itself) Example: SomeConstructor(int s) :some_vector(s*s, " " ){}//this will initialize some_vector to s*s elements of " " 2. Make class variable pegs a protected variable. 3) Make functions check_column_win, check_row_win, and check_diagonal_winprotected virtual functions. 4. Modify the overloaded stream functions to work with TicTacToe 3 or 4 InTicTacToe3
1. Create a class that inherits from TicTacToe. 2. Create a default constructor (no parameters). a. Create an initializer to initialize TicTacToe with a value of 3. Example: DeriveConstructor(): BaseConstructor(3){} 3. Create private functions check_column_win, check_row_win, and check_diagonal_win with no parameters that return a bool. 4. From TicTacToe copy the code from functions check_column_win, check_row_win, and check_diagonal_win to the functions in TicTacToe3. 5. In TicTacToe functions check_column_win, check_row_win, and check_diagonal_win , remove code leaving only the statementreturn false.
InTicTacToe4
1. Create a class that inherits from TicTacToe. 2. Create a default constructor (no parameters). a. Create an initializer to initialize TicTacToe with a value of 4. 3. Create private functions check_column_win, check_row_win, and check_diagonal_win with no parameters that return a bool. 4) Modify check_column_win, check_row_win, and check_diagonal_win to detect if game is over or board is full, (account for a vector of 16 (4x4 board)) Modify TicTacToeManager
1. Change the games vector to a vector of reference wrapper TicTacToe. Example: vector> accounts; 2. Change save_game TicTacToe parameter to a unique_ptr of TicTacToereference. a. In save_game make sure update_winner_count is the first statement (Use -> instead of . for get_winner). b. In save_game change games.push_back, add the move statement to game variable.
In main.cpp
1. Allow users to choose between a tic tac toe 3 or 4 game. a) Modify TicTacToe game (or whatever variable name you used), to unique_ptr to TicTacToe. (An instance of TicTacToe3 or 4 will be created in the next step) b) Prompt the user to play TicTacToe 3 or 4 (requires conditional to create correct instance) In the conditional structure Create an instance (make_unique) of TicTacToe3 or 4 c) Modify the TicTacToe manager save game function call to manager.save_game d)For TicTacToe variable, change .notation to -> operator. To test the homework changes modify the tic_tac_toe_test.cppfile as follows: Change instances of: TicTacToe board; to unique_ptr board (make sure to use make_unique to create an instance of TicTacToe3) change .notation to -> operator.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started