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 variation of a dictionary attack involves a dictionary attack combined with a brute force attack, and will slightly alter d
kipiarov [429]

Answer:

D. Hybrid

Explanation:

Hybrid attack is a dictionary attack combined with a brute Force attack, alter the dictionary word by adding numbers at the end of the password, spelling the word backward and slightly misspelling or adding special characters to the word.

Brute Force attack is a password hacking technique that continuously input various values to crack or guess a correct password value.

4 0
4 years ago
Read 2 more answers
What is a career pathway for ctso
Harman [31]
<span>CTSO is an acronym for Career and Technical Student Organization.  These are organizations specifically for students enrolled in CTE programs.  These organizations engage students through focus on CTE application activities such as developing and practicing leadership roles and applying specific occupational and academic content knowledge as an integral part of the instructional program.

they can work at alto of places like being a hair stylist, a engineer , game programmer, doctor, director, or a musician there really are a lot of careers to chose from       </span>
7 0
3 years ago
Read 2 more answers
These can be nodes in a computer network
Hunter-Best [27]

Answer:

Computers

Explanation:

Node is an electronic device. It is the Physical components that can send, receive or forward data.

Computer is an electronics devices and also have ability to send, receive or forward data. so this is the reason that, we can say computer is a node in computer network.

6 0
3 years ago
Which of the following allows the transmission of voice and often video communication over the internet?
spin [16.1K]
Voice Over IP (VOIP) is the option that allows the transmission of voice and often video communication over the Internet.
So, this doesn't refer to mobile or other telephone communication, but rather to the Internet solely. Applications that are examples of this type of technology are Skype, Teamspeak, Ventrilo, and others. This technology is becoming better and better with each day and will probably replace phones completely in the future.
8 0
3 years ago
Why is brainly not working it say im logged out rn but im not i cant acces anything but this
Grace [21]

Answer:

the answers are unlimited now so you cant sigh up but if you cant log in then one of the things you filled i. Might be wrong

Explanation:

3 0
4 years ago
Read 2 more answers
Other questions:
  • A spreadsheet has some values entered: Cell A1 contains 10, cell A2 contains 14, cell A3 contains 7. You enter in cell A4 the fo
    6·1 answer
  • What is heaven backwards?
    11·2 answers
  • Where may an operating system reside in a mobile device?
    5·1 answer
  • Does players report you on Mobile legends bang bang for playing your own Music while your playing yes or no
    11·1 answer
  • Design and implement a program (name it Youth) that reads from the user an integer values repressing age (say, age). The program
    6·1 answer
  • What are layers? Why would a layer be used?
    9·1 answer
  • What is digital scavenger hunting? A. An application that locates addresses B. A scavenger hunt where players use GPS and digita
    5·1 answer
  • Collaboration, listening, and negotiating are considered __________ skills.
    11·1 answer
  • How many combinations of 1s and Os can we make with 6 place values?
    12·1 answer
  • on early ethernet networks, all computers were connected to a single wire, forcing them to take turns on a local area network (l
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!