Question

In: Computer Science

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

C++

The program will call the start_game function with argument O or X to indicate first player and will keep track of the next player while 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 a constructor.
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. Error Message: Player must be X or O.
2)In function set player(private variable) to first_player function argument.
3) After the conditional branch statement, call the clear_board function

+

void mark_board(int position)

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

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 else player is X

-

New

void check_board_full

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

-

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 an Error
4) Use REQUIRE_THROWS_AS to verify game.mark_position(10) throws an Error
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 following order(this test case will eventually be the test for CAT tie case)

Solutions

Expert Solution

I develop code different way please see

first import header file , create global variable

function to show the current status of the gaming board

function name is display_board()....

function to get the player input and update the board

function name is player_turn().....

continue above function

function to get the game status e.g. GAME WON, GAME DRAW, GAME IN CONTINUE MODE

function name is gameover()....

main method...

output view

GAME DRAW

GAME WON

crazy code......!!


Related Solutions

Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O,...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated...
Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
Write a function called is_equal(). This function will take as an argument two integers. Call the...
Write a function called is_equal(). This function will take as an argument two integers. Call the is_equal function and supply two integers. You do not need to get the integers from the keyboard. Compare the two integers. If the two integers are equal, then print "equal". If the two integers are not equal, print "not equal". Call the function from your main code to execute the function. Sample output: equal Sample output: not equal
Write a C program using system call I/O to a) open an existing text file passed...
Write a C program using system call I/O to a) open an existing text file passed to your program as a command line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated content of the file
Write a C function to swap the first and last elements of an integer array. Call...
Write a C function to swap the first and last elements of an integer array. Call the function from main() with an int array of size 4. Print the results before and after swap (print all elements of the array in one line). The signature of the arrItemSwap() function is: void arrItemSwap(int *, int, int); /* array ptr, indices i, j to be swapped */ Submit the .c file. No marks will be given if your pgm does not compile...
(Multiple Select). First, indicate whether the following is an argument or not. Second, if it is...
(Multiple Select). First, indicate whether the following is an argument or not. Second, if it is an argument identify the conclusion. "Ethics is a matter of opinion. Different people and cultures have different beliefs about whether actions like stealing are right or wrong." Group of answer choices Yes, this is an argument. "Atmospheric carbon dioxide has increased substantially..." is the conclusion "it is likely that global warming is the result of burning fossil fuels" is the concluison No, this is...
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x contains an odd number of 1s (in its binary representation) and 0 otherwise. You can consider x as a four byte integer, i.e. w = 32 bits. Constraint: Your solution can use at most 12 arithmetic, bitwise, and logical operations.
In C Write a main function with a function call to a function called GetLetter which...
In C Write a main function with a function call to a function called GetLetter which has two double arguments/parameters. The function returns a character. Declare and initialize the necessary data variables and assign values needed to make it executable and to prevent a loss of information
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT