Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The players take turns making moves and the program keeps track of whose turn it is. Player X moves first. The program should run a loop that:

Answers

Answer 1

#include <iostream>

using namespace std;

//function prototypes

void showBoard(char[][3]);

bool checkWinner(char[][3], char);

void playerMove(char[][3], char);

int main()

{

  //declare variables needed

  //declare 2D array for the board

  //and initialize with all *

  char board[3][3] = {{'*', '*', '*'},

                      {'*', '*', '*'},

                      {'*', '*', '*'}};

  int moves = 0;  //variable to keep track

                  //of number of moves

                  //to determine tie

  cout << "TIC - TAC - TOE\n\n";

  //while loop to repeat until 9 moves are done

  while(true){

      //display board

      showBoard(board);

      cout << "Player 1 moves\n";

      //get player X move

      playerMove(board, 'X');

      //increment moves counter

      moves++;

      //if this is a winning move

      //store winner and terminate

      if(checkWinner(board, 'X')){

          showBoard(board);

          cout << "\nPlayer 1 (X) wins!\n";

          return 0;

      }

      //if 9 moves are done

      //break from loop

      if(moves == 9)

          break;

      //display board again

      showBoard(board);

      cout << "Player 2 moves\n";

      //do the same thing for player O

      playerMove(board, 'O');

      moves++;

      if(checkWinner(board, 'O')){

          showBoard(board);

          cout << "\nPlayer 2 (O) wins!\n";

          return 0;

      }

  }

  //if we have gone this far and program

  //still has not terminated (no winner)

  //it means this is a tie

  showBoard(board);

  cout << "This game is a tie!\n";

  //return 0 to mark successful completion of program

  return 0;

}

//this function is helpful because we need to show

//the board repetitively during the program

void showBoard(char board[][3]){

  cout << endl;

  //loop on the rows

  for(int row = 0; row < 3; row++){

      //loop on the columns

      for(int col = 0; col < 3; col++)

          cout << board[row][col] << "    ";

      //display newline after each row

      cout << endl << endl;

  }

  cout << endl;

}

//this function checks if second argument

//is a winning player

bool checkWinner(char board[][3], char player){

  //boolean variable to check

  //for winner later

  bool flag;

  //CHECK FOR WINNER IN ROWS

  for(int row = 0; row < 3; row++){

      //initialize flag to true

      flag = true;

      //loop within a row

      for(int col = 0; col < 3; col++){

          //Notice that the right part of the

          //assignment operator, is an expression

          //with a relational operator (==)

          //this expression will yield either

          //true (1) or false (0)

          //while flag is already true (1)

          //if multiplied by true (1) will result

          //in true(0), or multiplied by false (0)

          //will result in false (0)

          flag *= (board[row][col] == player);

      }

      //after checking within row, if the flag

      //is still true at this point, it means we have

      //three chars of the same kind within the row,

      //thus we have a winner

      if(flag)

          return true;

      else

          continue;

  }

  //CHECK FOR WINNER IN COLUMNS

  //using a similar logic

  for(int col = 0; col < 3; col++){

      flag = true;

      for(int row = 0; row < 3; row++){

          flag *= (board[row][col] == player);

      }

      if(flag)

          return true;

      else

          continue;

  }

  //CHECK FIRST DIAGONAL (row = col)

  //reset flag to true

  flag = true;

  //check diagonal

  for(int i = 0; i < 3; i++){

      flag *= (board[i][i] == player);

  }

  //check if there is winner

  if(flag)

      return true;

  //CHECK OTHER DIAGONAL (row = 2 - col)

  //reset flag to true

  flag = true;

  //check diagonal

  for(int col = 0; col < 3; col++){

      flag *= (board[2-col][col] == player);

  }

  //check if there is winner

  if(flag)

      return true;

  //if all of these have been checked

  //and function still has not returned,

  //it means there is no winner

  return false;

}

//this function gets a move from the player,

//checks if it is valid, and if yes it puts

//it on the board

void playerMove(char board[][3], char player){

  //variables to store user move

  int row, col;

  //get user move

  cout << "Row: ";

  cin >> row;

  cout << "Col: ";

  cin >> col;

  //check if this is valid move

  //you have to check if that tile has

  //already been marked, or if tile

  //of choice is out of bounds of board

  while(board[row-1][col-1] != '*' ||

        row > 3 || row < 0 ||

        col > 3 || row < 0)

          {

      cout << "Invalid move! Try again\n";

      cout << "Row: ";

      cin >> row;

      cout << "Col: ";

      cin >> col;

  }

  //after validation, mark new move

  board[row-1][col-1] = player;

}

Answer 2

Answer:

if on edgen. The answer is c

Explanation:


Related Questions

Which of the following is a characteristic of TIFFs?

universal standard for image file formats

cross-platform

the one version of TIFF that exists

only available as a vector graphic
please help

Answers

Answer:

What are the characteristics of a TIFF file?

A TIFF file supports grayscale as well as RBG,CMYK, and LAB color space. The format allows a color depth of up to 16 bits per color channel and is therefore ideal for data exchange during a RAW conversion. The abbreviation TIFF, or more rarely TIF, stands for “Tagged Image File Format”.

Answer:

universal standard for image file formats

Nhich of these is an optical medium of storage?

Answers

Answer:

Compact Disks, DVDs, Floppy Drives, Hard Disk Drives

How many categories of computer do we have?

Answers

Answer:

The 10 types of computers include personal computers, desktops, laptops, tablets, hand-held computers, servers, workstations, mainframes, wearable computers and supercomputers.

A victimless crime is committed when
|. Select 3 options.
someone downloads a pirated song or video
a copyrighted image is used without permission
a stranger accesses your internet banking
a person downloads and uses pirated software
a hacker sells a company's financial statements

Answers

Someone downloads a pirated song or video a copyrighted image is used without permission and a person downloads and uses pirated software.

A victimless crime is committed when a copyrighted image is used without permission 2. a stranger accesses your internet banking 3. a hacker sells a company’s financial statements.

Victimless crimes are illegal acts that break the laws, but there is no single victim of the crime. They are against social values and laws. A copyrighted image is used without permission

Examples are gambling, traffic violations, etc. Thus, Victimless crimes differ from other types of crime because it does not have an identifiable victim. This crime is against laws and social values and beliefs.

To know more about victimless crimes, visit:

brainly.com/question/17251009

#SPJ6

Text based game project 1

Answers

Answer:

What is your question?

Explanation:

These are raised as livestock for meat and milk EXCEPT one
A. Hog
B. Goat
C. Carabao
D. Cattle

Answers

The livestock that is not raised for  meat and milk is  hog.

What are animals raised for meat?

Livestock are known to be some domesticated animals that are said to be raised in an agricultural farm to give labor and produce things such as meat, eggs, milk, etc.

The animals that are raised for their meat and milk are:

Boar BroilerCattle, etc.

Learn more about animals from

https://brainly.com/question/25897306

explain declaration and initialization of one and two dimensional arrays with example

Answers

The declaration and initialization of arrays involves creating and using the arrays

How to declare an array?

Assume the programming language is Java.

To declare and initialize an array, we make use of:

One dimensional array: Data-Type Array-name [] = {List of array values}Two dimensional array: Data-Type Array-name [] [] = {List of array values}

Assume the array name of the one dimensional array is num, and the data type is integer.

The following can be used to declare and initialize the array to have 5 elements

int num [] = {1,2,3,4,5}

Assume the array name of the two dimensional array is num, and the data type is integer.

The following can be used to declare and initialize the array to have 2 rows and 3 columns

int num [][] = {{1,2},{3,4},{5,6}}

Read more about arrays at:

https://brainly.com/question/22364342

Can someone give me answers for 1-4

Answers

Answer:

you want me help u with this one?

2. The different amount of shades of color

3. The artist had given every marvel or DC or villian the color that fit them and the texture is also very nice in the picture.

4. The artist maybe could make the pic a little bit more high quality cause in the image is sort of blurry and you cant really see the further people that well.

What does the standard deviation of a set of data tell you?
O A. The smallest data value
B. Whether the data are spread out or not
O C. How many data points there are
O D. The maximum value of the data
SU

Answers

Answer: It tells us about how our set of data is spread out as compared to our mean or expected value.

Explanation: Note: Standard deviation is represented by Greek Letter sigma.For example: A teacher in a class of particular students takes a learning ability test from the students. Average or mean marks of students is 52 with +/- 10 marks. Then 1σ (Sigma = standard deviation) it means 1 standard deviation = 68% students will lie in between 52 + 10 =62 marks and 52-10 = 42 marks region.  2σ (2 standard deviation) means among the students 95% of them will lie between 52 + 20 =72 and  52-20= 32 marks region.3σ (3 standard deviation) means 99.7% of the students will lie in the region where 52 + 30 = 82 and 52 – 30 = 22 marks region.  So for 3σ (3 Standard Deviations), only 0.3% of the total students deviate +/-30 marks from the average. It means 0.15% students will have marks less than 22 and 0.15%  students will have marks greater than 82.  In the schematic attached, I have tried to make you understand through a diagram. Please refer to the schematic 1.  It tells us about the how our set of data is spread out as compared to our average or mean. And distance from mean can be calculated through number of standard deviations that the data is how much below or above the average.For example:For 1σ 68% students will come under the curve of “Average Learners”  and rest of 32% will come under the curve of “Poor Learners” and “Very Talented Learners”.For 2σ 95% of the students will come under the curve of “Average Learners”  and rest will come under the curve of “Poor Learners” and “Very Talented Learners”.For 3σ 99.7% of the students will come under the curve of “Average Learners” and rest of 0.3% will come under the curve of “Poor Learners” and “Very Talented Learners”.

what is the future of web development

Answers

Answer:

Creating websites that can execute automated tasks and new programing languages revolving around web development.

Explanation:

Type the correct answer in the box. Spell the word correctly.

Which firewall monitors traffic from the DMZ to the LAN?

When a DMZ is set up using dual firewalls, the___

-end firewall monitors traffic moving from the DMZ toward the LAN while the ___

firewall monitors the traffic from the Internet toward the DMZ.

Answers

The firewall that monitors traffic from the DMZ to the LAN is the second, or internal (dual-firewall)

Which firewall manages traffic from the DMZ to the LAN?

In this kind of traffic, the second, or internal, firewall is known to be the one that gives room for traffic to move from the DMZ to the internal network.

Note that the dual-firewall approach is seen as a very secure way due to the fact that  two devices have to be compromised before any kind of attacker can be able to gain access into the internal LAN.

When a DMZ is set up using dual firewalls, the web server is placed inside the DMZ and the private network is often placed behind the DMZ.

Learn more about firewall from

https://brainly.com/question/13693641

In this lab, you will implement a temperature converter in JavaScript. The user may type a temperature in either the Celsius or Fahrenheit textbox and press Convert to convert the temperature. An image displays based on the converted temperature. (see the image uploaded here)

Answers

Use the knowledge in computational language in JAVA to write a code that convert the temperature.

How do I convert Celsius to Fahrenheit in Java?

So in an easier way we have that the code is:

Fahrenheit to celsius:

/* When the input field receives input, convert the value from fahrenheit to celsius */

function temperatureConverter(valNum) {

 valNum = parseFloat(valNum);

 document.getElementById("outputCelsius").innerHTML = (valNum-32) / 1.8;

}

Celsius to Fahrenheit:

function cToF(celsius)

{

 var cTemp = celsius;

 var cToFahr = cTemp * 9 / 5 + 32;

 var message = cTemp+'\xB0C is ' + cToFahr + ' \xB0F.';

   console.log(message);

}

function fToC(fahrenheit)

{

 var fTemp = fahrenheit;

 var fToCel = (fTemp - 32) * 5 / 9;

 var message = fTemp+'\xB0F is ' + fToCel + '\xB0C.';

   console.log(message);

}

cToF(60);

fToC(45);

See more about JAVA at brainly.com/question/12975450


Why do crawlers not use POST requests?

Answers

Answer:

Generally they do not do POST requests. This is just the current state of affairs and is not dictated anywhere, I believe. Some search engines are experimenting with crawling forms, but these are still GET requests.Explanation:

9) Which date is assigned the serial number of 1?


A. January 1, 1700


B. January 1, 2000


C. January 1, 1900


D. January 1, 1800

Answers

Answer:

c) January 1, 1900

Explanation:

January 1, 1900 (1 - 1 - 1900) is assigned the serial number of 1. The serial number 1 represents January 1, 1900. Hence, option (c) is the correct answer.

nivel 1: operadores pedir 2 números al usuario y Sumarlos, restarlos, multiplicarlo y dividirlos ​

Answers

Answer:

¿Esta pregunta no tiene ningún sentido?

Explanation:

¿que estas pidiendo?

How many bytes can be stored in a 4gb flash drive

Answers

Answer:

4,294,967,296; theoretically

Explanation:

There is 1024 bytes in a kb, 1024 kb in a mb, 1024 mb in a gb.

So we can use 1024³ as a multiplier to convert gb->byte.

1024³ * 4 = 4,294,967,296 bytes.

However, in practice hardrives always have less useable storage than the quoted amount.

The following code appears in a sort function. Will this function sort in increasing order (smallest first) or decreasing order (largest first)? Explain your answer if (list[index] < list[index + 1]) { temp = list [index]; list[ index] = list [index +1]; list[index +1] = temp; }

Answers

A sort function sorts in an ascending or desceding order

The true statement is that the function would sort in decreasing order.

What is a sort function?

A sort function is a code segment that is used to reorder a list in ascending or descending order, when called or evoked

The order of the sort function

The code segment is given as:

if (list[index] < list[index + 1]) {

temp = list [index];

list[ index] = list [index +1];

list[index +1] = temp;

}

In the above code, we can see that the code compares a list element with the next element on the list, and the larger value comes to the front

This means that the sort function sorts in decreasing order

Read more about code segments at:

https://brainly.com/question/16397886

6. Which of the following items is not a storage
medium?
A. Plotters
B. Zip disk
C. Hard disk
D. Memory stick

Answers

Answer:

Plotters

Explanation:

A 'plotter' is an external hardware device like a printer used with a computer to 'print vector graphics' - basically in english it no hold storage like that

a) Explain any two problems associated with the existing system used by the organization. (25 marks)​

Answers

Answer:

Lack of Strategy

Many of the most common MIS issues can be traced back to a lack of a solid strategy. Information systems leaders are well aware of the many tools available to gather data on their network. But putting that information to use is often a challenge.

At one time, technology departments served as a separate operation, providing tech support and keeping an organization’s server equipment running. Today, MIS leadership often sits alongside other business leaders, working together to ensure that the technology being used supports the overall mission of the company moving forward.

Meeting Organizational Needs

MIS plays an ever-increasing role in organizations, with professionals relying on technology for every aspect of operations. Sales and marketing rely heavily on customer relationship software to track client interactions, for instance, while accounting needs its own software for billing, invoicing and financial tracking.

With more than half of all companies now relying on big data analytics, MIS is playing an even more important role. Before making a decision, today’s management teams are likely to pull reports on existing activity to ensure they use facts rather than make educated guesses.

Explanation:

In programming 2+6 is an example of what math

Answers

Answer:

[tex]beinggreat78~here~to~help.[/tex]

2 + 6 in programming is an example of math. It is the same as in the real world. Plus signs in coding are also a form of string concatenaction, the term used for combining two strings into one, or a variable into a string.

What should I do instead of listen to music?

Answers

You could watch a movie
Learn something new that you are interested in

i need the full code for 6.1.3 code hs circles and squares please answer please help

Answers

In this exercise we have to use the knowledge in computational language in python  to write a code with circles and squares.

how to draw geometric figures in python?

inputs = 100

radius

   draw_circle(radius);

   pendown()

   begin_fill()

   circle(radius)

   end_fill()

   penup()

left(90)

forward(radius*2)

right(90)  

penup()

setposition(0,-200)

color("gray")

bottom_radius = int(input("What should the radius of the bottom circle be?: "))

draw_circle(bottom_radius)

draw_circle(bottom_radius)

See more about python at brainly.com/question/18502436

What year was internet inverted

Answers

[tex]\large\blue{\mid{\underline{\overline{\tt { →\:January \:1, 1983}\mid}}}}[/tex]

ARPANET→Advanced Research Projects Agency Networkthe forerunner of the Internet.

[tex]\purple{\rule{15mm}{2.9pt}} \red{\rule18mm{2.5pt}} \orange{ \rule18mm{2.5pt}}[/tex]

[tex]\sf{\:мѕнαcкεя\: ♪...}[/tex]

Which method adds 10 to the right end of the array?
myArray.
insert
(10)

Answers

JavaScript has a set of mutator functions that allow you to modify the contents of an array without referencing the individual elements.To add to to myArray we us the push() method

Adding Elements to an Array

To add to to myArray we us the push() method

(10)

myArray.push(10)

There are two mutator functions for adding elements to an array: push() and unshift(). The push() function adds an element to the end of an array:

var nums = [1,2,3,4,5]; print(nums); // 1,2,3,4,5 nums.push(6);

print(nums); // 1,2,3,4,5,6

var nums = [1,2,3,4,5]; print(nums); // 1,2,3,4,5 nums[nums.length] = 6; print(nums); // 1,2,3,4,5,6

Learn more about arrays here:

https://brainly.com/question/24275089

It would be Array.append(10), so append is the answer.

It is possible to publish a presentation online. True False

Answers

Answer:

It should be true

Explanation:

I don't see why it wouldn't

8. Show that x = xy + xy'
a) Using truth tables
b) Using Boolean identities

Answers

Answer:

B

Explanation:

Cause Show that x =Xy plus xy' is common = is Using Boolean Identify? tY me

list the factors that influenced the advancement of AI in recent years​

Answers

Answer:

In any case, there are 5 factors which are driving the development of Artificial Intelligent and other technologies of Big Data, ML, etc.

Next-Generation Computing Architecture. ...

Open Data. ...

Growth in Deep Neural Networks. ...

Legal and Ethical Issues. ...

Historical Datasets.

Ncomputing and thin client
what it is
why is done , how it works and how it's
done ​

Answers

The term NComputing  is known to be a form of desktop virtualization company that is said to creates hardware and software to form virtual desktops.

The term Thin clients is known to be virtual desktops. They help a lot of users at the same time to share a single operating system instance.

What is the aim of a thin client?

In Ncomputer networking, a thin client is known to be a kind of low-performance computer that is known to be optimized and used for setting up a remote connection.

It is often used with a server-based computing system. The server here is one that often does most of the work, such as launching software programs, etc.

Learn more about Ncomputing from

https://brainly.com/question/12629145

If you determine that the hard drive is experiencing excessive use but the Windows Experience Index reports that memory is the system bottleneck, which component do you upgrade first: memory or the hard drive? Why?

Answers

The reason why is it is good to use an Upgrade memory is because low amounts of memory can lead to much use of the hard drive and based n the fact that it is not costly to upgrade memory than to upgrade the hard drive.

What is upgrading memory?

This is known to b an act done so as to improve the performance of a computer.

It is often known as a RAM or system memory upgrade. An upgrade implies that one is adding memory modules along with the ones that were there or replacing the old ones. It is less costly when compared to hard drive upgrade.

Learn more about Upgrade memory  from

https://brainly.com/question/13196228

positive and negative of adblock plus

Answers

Answer:

Pros and cons of ad blockers

Remove distracting ads, making pages easier to read.

Make web pages load faster.

Keep advertisers from tracking you across websites.

Reduce bandwidth (especially important with mobile devices)

Reduce battery usage (again, important for mobile devices)

p

Other Questions
propiedad directa concepto solve: answer is x is greater than or equal to 3. Midlife crisis or transition is naturally accompanied by severe depression. please select the best answer from the choices provided t f Find the distance between the points.? Help 40 points!!! Which sentence uses the word source correctly?Most sources show that small dogs tend to be more nervous.The scientist published a source that was seven pages long.The article sourced that all dogs can vary in personality Micah, a young adult, reads a diary he kept in high school, laughing at his former self. He wonders how he couldhave thought he was so deeply in love that he'd found his soulmate at the age of 13. What part of Micah's brainhas developed since he was 13 to give him this perspective? I need a mnemonic for the reactivity server of metals pleasePotassiumSodiumLithiumCalciumMagnesiumAluminium CarbonZincIronNickelTin LeadHydrogenCopperMercurySilverGoldPlatinum Area of polygons please help What are book-length poems that are often associated with asociety's cultural values? NovelsSonnetsHaikuEpicsVillanelle sorry Ballads Would appreciate some help Why do so some birds addict to smoke? Explain the places occupied by grass, a rabbit, and a wolf in an energy pyramid. Weisss paint store uses a (q, r) inventory system to control its stock levels. for a particularly popular white latex paint, historical data show that the distribution of monthly demand is approximately normal, with mean 28 and standard deviation 8. replenishment lead time for this paint is about 14 weeks. each can of paint costs the store $6. although excess demands are back-ordered, the store owner estimates that unfilled demands cost about $10 each in bookkeeping and loss-of-goodwill costs. fixed costs of replenishment are $15 per order, and holding costs are based on a 30 percent annual rate of interest.a. what are the optimal lot sizes and reorder points for this brand of paint?b. what is the optimal safety stock for this paint? Can you help me with this Describe ONE change in political organization necessary to facilitateurban industrial development in a developing countryYour answer Sam is climbing 9000 m every 30 minutes. How many meters will he climb in 1 hour How are the meanings of compensate and replace related? Can anyone help me please A class has 26 students. Each student has to present a project to the class. To decide the order, the teacher writes every letter in thealphabet on pieces of paper and puts it in a hat. What is the probability that the first letter drawn is not a vowel?A. 7/26B. 19/26C. 21/26D. 5/26 Why should consumers rights be ensured? Write in a sentence.