1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marizza181 [45]
3 years ago
13

Declare and implement a function called gameOver.gameOver receives a single 3x3 char[] [] array as a parameter, representing a t

ic-tac-toe board, with each cell containing either a X, a 0, or a (blank space). gameOver should return x if x has won the game, o ifo has won the game, and a blank space (' ') otherwise. Do not check the diagonals!
Computers and Technology
1 answer:
svlad2 [7]3 years ago
7 0

Answer:

The function in C++ is as follows:

char gameOver(char arr[][3]){

   char winner = ' ';

   if((arr[0][0] == 'X' && arr[0][1] == 'X' && arr[0][2] == 'X') ||(arr[1][0] == 'X' && arr[1][1] == 'X' && arr[1][2] == 'X') || (arr[2][0] == 'X' && arr[2][1] == 'X' && arr[2][2] == 'X')||(arr[0][0] == 'X' && arr[1][0] == 'X' && arr[2][0] == 'X') ||(arr[0][1] == 'X' && arr[1][1] == 'X' && arr[2][1] == 'X') || (arr[0][2] == 'X' && arr[1][2] == 'X' && arr[2][2] == 'X')){

       winner = 'X';

   }

   else if((arr[0][0] == 'O' && arr[0][1] == 'O' && arr[0][2] == 'O') ||(arr[1][0] == 'O' && arr[1][1] == 'O' && arr[1][2] == 'O') || (arr[2][0] == 'O' && arr[2][1] == 'O' && arr[2][2] == 'O')||(arr[0][0] == 'O' && arr[1][0] == 'O' && arr[2][0] == 'O') ||(arr[0][1] == 'O' && arr[1][1] == 'O' && arr[2][1] == 'O') || (arr[0][2] == 'O' && arr[1][2] == 'O' && arr[2][2] == 'O')){

       winner = 'O';

   }

   return winner;

}

Explanation:

The function checks for the winning character by checking for matching rows and matching columns.

When either X or O fall in the any of the following 6 conditions , then that character (X or O) wins.

The position are:

Rows: (1) 00, 01 and 02 (2) 10, 11 and 12 (3) 20, 21 and 22

Columns: (4) 00, 10 and 20 (5) 01, 11 and 21 (6) 02, 12 and 22

So, the explanation is:

This defines the function gameOver

char gameOver(char arr[][3]){

This initializes winner to blank space

   char winner = ' ';

If any of the condition stated above matches X, then X wins

<em>    if((arr[0][0] == 'X' && arr[0][1] == 'X' && arr[0][2] == 'X') ||(arr[1][0] == 'X' && arr[1][1] == 'X' && arr[1][2] == 'X') || (arr[2][0] == 'X' && arr[2][1] == 'X' && arr[2][2] == 'X')||(arr[0][0] == 'X' && arr[1][0] == 'X' && arr[2][0] == 'X') ||(arr[0][1] == 'X' && arr[1][1] == 'X' && arr[2][1] == 'X') || (arr[0][2] == 'X' && arr[1][2] == 'X' && arr[2][2] == 'X')){</em>

<em>        winner = 'X';</em>

<em>    }</em>

If otherwise that it matches O, then O wins

<em>    else if((arr[0][0] == 'O' && arr[0][1] == 'O' && arr[0][2] == 'O') ||(arr[1][0] == 'O' && arr[1][1] == 'O' && arr[1][2] == 'O') || (arr[2][0] == 'O' && arr[2][1] == 'O' && arr[2][2] == 'O')||(arr[0][0] == 'O' && arr[1][0] == 'O' && arr[2][0] == 'O') ||(arr[0][1] == 'O' && arr[1][1] == 'O' && arr[2][1] == 'O') || (arr[0][2] == 'O' && arr[1][2] == 'O' && arr[2][2] == 'O')){</em>

<em>        winner = 'O';</em>

<em>    }</em>

This returns the winner (either O, X or blank)

   return winner;

<em>See attachment for complete program which includes the main</em>

Download cpp
You might be interested in
What other identifiers would you need to alter in a cloned virtual machine to be sure it was unique? What might happen if these
Romashka [77]

Answer:

Following identifiers needs to be altered in cloned VM.

  1. Changing the IP address
  2. Selecting Ethernet Ports
  3. Rename the Pointers
  4. Renaming the Second Disk Drive
  5. Host names must be unique
  6. Rename the VM name

Explanation:

When we clone the VM, we have to make sure that Cloned VM should have unique system information and network addresses in and out of guest OS.

If UUID’s of all cloned VM's are different then DHCP will get separate ip addresses for those. Suppose if the IP addresses are static or If the IP address was hardcoded then it has to be changed to new IP address manually. If this is not done then it will cause duplicate IP’s and will cause networking issues.

When Cloned VM is created then the ethernet port has to be chosen correctly to make sure that LAN networking is correct.

You should specify the disk capacity. If you choose disk capacity as single file then it will create one vmdk file. So, specify the correct disk capacity, If you did not choose the disk file as single file then you may end up having multiple .vmdk files. So in that case you need to rename the pointers of copy of vmdk files.

Rename the Second Disk Drive. For example : You may find two VM files with VM Copy.vmdk, So you have to rename second disk to VM Copy-1.vmdk or any other name.

The cloned VM copies the parent virtual machine and it also includes the VM name. To avoid problems caused by having VM's with duplicate names on the network, give the VM in the cloned VM a unique name.

You have to make sure that hostnames are different as well. Hostname resolution will lead to conflict if its same on both VM's.

7 0
4 years ago
How do i mark brainliest?
neonofarm [45]

Answer: There is a crown button that should pop up by the question you have asked.

Explanation: ...

8 0
3 years ago
Read 2 more answers
Select the protocol data units.
Masja [62]

Answer: 4. Data 2. segment  7.packet 3.frame  1.bit

Explanation:

3 0
3 years ago
Read 2 more answers
Mix ‘em Let s1 and s2 be 2 c-strings of the same length. Write a function char* mixem(char*s1, char* s2) which returns a c-strin
Shkiper50 [21]

Answer:

See Explaination

Explanation:

#include <iostream>

#include <string.h>

using namespace std;

char *mixem(char *s1, char *s2);

int main() {

cout << mixem("abc", "123") << endl;

cout << mixem("def", "456") << endl;

return 0;

}

char *mixem(char *s1, char *s2) {

char *result = new char[1 + strlen(s1) + strlen(s2)];

char *p1 = s1;

char *p2 = s2;

char *p = result;

while (*p1 || *p2) {

if (*p1) {

*p = *p1;

p1++;

p++;

}

if (*p2) {

*p = *p2;

p2++;

p++;

}

}

*p = '\0';

return result;

}

5 0
3 years ago
Pls help!!!!! I need these questions
g100num [7]

Answer:

online identity for the first one and none of the above for the second one:)

8 0
3 years ago
Read 2 more answers
Other questions:
  • How to Ctrl + shift + F4 but in a HP laptop?​
    8·2 answers
  • In the following piece of css code what is the property ?
    9·1 answer
  • You wish to lift a 12,000 lb stone by a vertical distance of 15 ft. Unfortunately, you can only generate a maximum pushing force
    8·1 answer
  • Five aplications of ict​
    10·1 answer
  • Why are some studs and bolts undercut in the middle?
    11·1 answer
  • which of the following is the full path and filename of the file that contains information about which interrupt request (IRQ) c
    10·1 answer
  • True or False. Over the past few years, the hacking community has engaged in more "lone wolf" types of hacking activities as opp
    7·1 answer
  • Which two of the following skills are important for a meteorologist
    12·1 answer
  • By what other name can the folders in Windows 7 be called?
    5·1 answer
  • Using web-safe fonts and colors is something you can do to increase blank
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!