C++ The program will call the start_game function with argument O or X to indicate first player...

50.1K

Verified Solution

Question

Programming

C++

The program will call the start_game function with argument O orX to indicate first player and will keep track of the next playerwhile players take turns marking the board until the board is full.This version of the game only plays one game.

Class Specifications


TicTacToe class does not have aconstructor.
Member Functions and Member(variable)Specifications
+ = public
- = private

public/private

New/Update/NoUpdate

Function/Data Member

Functionality of function or data member

+

New

bool game_over

No parameters
1) return check_board_full function return value

+

Update

void start_game(string first_player)

1) first_player function argument value must be X or O;otherwise, throw an Error exception when value is not X or O. ErrorMessage: Player must be X or O.
2)In function set player(private variable) to first_player functionargument.
3) After the conditional branch statement, call the clear_boardfunction

+

void mark_board(int position)

1) Value of int must be in the range 1 to 9; otherwise, throw anError exception if value not in this range. Error Message: Positionmust be 1 to 9.
2) Private data player can’t be empty “”, throw an Error exceptionif player variable is “”. Error Message: Must start gamefirst.

3) Call set_next_player private function

+

string get_player() const

Return the next_player value

+

New

void display_board const

No parameters
Iterate vector of strings pegs to
Display a tic tac toe board in 3x 3 format

private functions

-

void set_next_player()

Set next_player. If private variable player X, player is O elseplayer is X

-

New

void check_board_full

No parameters
1) return false if vector of strings pegs has available slot bychecking for a “ “(space)in each element. Otherwise returntrue

-

New

void clear_board const

No parameters
1) Set all 9 elements to a “ “ (space)

Class private Data

-

string player

Class member variable

New

vector of string pegs

Class member variable
1) (initialize to 9 “ “(spaces)



UNIT TEST CASES

Required Test Cases for Assignment (write the code in/homeworks/tic_tac_toe_test/ tic_tac_toe_test.cpp)

Test Case Name

Steps to Test

Test Mark Position accepts values from 1 to 9 only

1) Create an instance of TicTacToe game
2) Call the start game function
3) Use REQUIRE_THROWS_AS to verify game.mark_position(0) throws anError
4) Use REQUIRE_THROWS_AS to verify game.mark_position(10) throws anError
5) Call mark board 5 to show that an Error is not thrown.
  

Test game over if 9 slots are selected.

1)Create an instance of TicTacToe game
2)Call the start game function
3)Call mark board 9 times using numbers 1 to 9 in the followingorder(this test case will eventually be the test for CAT tiecase)

Answer & Explanation Solved by verified expert
3.7 Ratings (678 Votes)
I develop code different way please seefirst import header file create global    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students