Simulation of checking tic-tac-toe board

Assignment Help Programming Languages
Reference no: EM131198930

You must do this assignment correctly as described below. 

If you do not follow the directions or break the rules you will receive a 0 score.

Simulation of checking tic-tac-toe board for wins by counting X and O in rows, columns and diagonals.

in a loop for array sizes 3X3, 4X4, 5X5

Fill the array of characters with either X or O.

Print the array

Count number of X and O in each row, each column and each diagonal and print the totals.

Extra credit (10%) while printing counts print wins for X and/or O

You must correctly use the variables and functions as given below.

You must use the outer for loop that varies the size of the array. 

That size must control the loops that fill, print and count.

All printing of counts must have labels for which row, column or diagonals the counts are for.

You must use loops, as demonstrated in class, to count the X and O in each direction.

Functions:

printArray(char array[5][5], int size) // row by row with label showing size

               int row, col;

countRows(char array[5][5], int size) // prints a count of X and Os for each row extra prints wins

    int row, col, xCount, oCount;

countColumns(char array[5][5], int size) // prints a count of X and O for each column, extra credit prints wins

int row, col, xCount, oCount;

countDiags(char array[5][5], int size)  // prints a count of X and O for both diagonals, extra credit wins

int row, col, xCount, oCount;

// single loop (1) to count top left to bottom right

// print diagonal's counts with label

// single loop (1) to count other diagonal

// print other diagonal's counts with label

int main(intargc, char * argv[] ){

               int row, col, size;

               char array[5][5];

               srand((unsigned)time(NULL)); // seedy stuff

               for (size = 3; size <= 5; size++) {

                        // fill the array

                              for (row = 0; row < size; row++)

                                             for (col = 0; col < size; col++)

                                                            array[row][col] = (rand() % 2) == 0 ? 'X' : 'O';

// print array: printArray(array, size)

 // print each row's counts: countRows(array, size)

  // print each column's counts: countColumns(array, size)

// print both diagonal's counts countDiags(array, size)

               } // end outer array size loop

Hints:

Do it for one size array first.  Do each part and test before moving on to the next.  Get fill and print array working, then rows etc.

Remember size 5 is 0-4 indexes.

Don't forget to reset the xCount and oCount to 0 after each row or column part of the loops.

Once it works for size 3 do it for 3, 4, and 5 using the outer for loop.

Reference no: EM131198930

Questions Cloud

What was the velocity of circulation in 2011 : Fisheria is a country in which the quantity theory of money operates. The country has a constant population, capital stock, and technology. In 2010, real GDP was $300million, the quantity of money was $60million, and the velocity of circulation of..
Supply and demand drive the transportation industry : Please discuss how supply and demand drive the transportation industry? In your opinion, how does the transportation industry affect the environment?
Majority of purchasing organisations : A recent report highlighted that the main measure of performance used by the majority of purchasing organisations was reduced costs.Propose other sets of performance measures that could be applied by purchasing organisations to assess their contri..
Large fraction of us health care costs : The fact that such a large fraction of U.S. health care costs are spent on people in their last six months of life has led many people to call the American health care system "wasteful."- Why might this be an overgeneralization?
Simulation of checking tic-tac-toe board : Simulation of checking tic-tac-toe board for wins by counting X and O in rows, columns and diagonals - You must use loops, as demonstrated in class, to count the X and O in each direction.
Identify the specific government health programs : Select a health policy issue from the list below. Analyze the policy issue using the given criteria. Assume that you must advocate for or argue against the policy issue in front of a Congressional health committee.
Find out the organizational behavior : Colin Powell is a retired four star general and was Commander of the United States Army Forces Command.  He also served as Secretary of State under George W. Bush and was his National Security Advisor.  Listen to Powell talk about Leadership in th..
Find the lowest price at which the product would be supplied : For each 25% increase in the unit price, 200 more calculators are supplied. When the price per calculator is P400, 500 more calculators are supplied.
National health insurance system like canadas : One disadvantage of a national health insurance system such as Canada's is "queuing"-people. - What elements of a national health insurance system could lead to this situation?

Reviews

Write a Review

Programming Languages Questions & Answers

  Evaluate a problem of perl language

When a user enters 101 for a temperature the program states the patient has expired which is not the correct response. How do I correct the problem.

  Write program using while loop to output squares of integers

Write a program that uses while loop to perform the following steps:Output the sum of all the even numbers between firstnum and secondnum inclusive. Output all the numbers and their squares between firstnum and secondnum inclusive.

  Which quality control method should the manager adopt. why

Type I error probability is defined as the conditional probability of rejecting a good lot. Type II error probability is defined as the conditional probability of accepting a poor quality lot.

  Write a function that accepts an array a as input and

write a function that accepts an array a as input and searches the contents of the array for elements in three

  Implement a program that processes an input file

Implement a program that processes an input file by changing every occurrence of an old string into a new string. (e.g., the usage is: chstr.pl file oldstring newstring, chstr.pl is your program name, file, oldstring and newstring are parameters ..

  Write a trigger for total percentage of all appointments

Write a trigger on Works department to ensure the following requirement; the total percentage of all appointments for an employee must be fewer than 100%.

  Design a program that displays the acidity level

The decision structure part of the program is missing. It should display the correct solution from the right column of the table.

  Design a class named rectangle to represent a rectangle

(The Rectangle class ) Following the example of the Circle, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The defa..

  Create the program for iteration control structure

Iteration Control Structure create the program which models worm's behavior - Worm can enter apple when it is in body length of apple.

  During the middle ages

During the Middle Ages, to determine the successor to the throne of France, the French used the Salic law. It is formulated as follows: the next to the throne is the living male descendant of the most direct male royal. Male royal here means that ..

  Write program to prompt user to enter year-find leap year

Write down program to prompt the user to enter year, and then tells user whether it is leap year. If user doesn't enter valid year (i.e., a positive integer).

  Two-dimensional array to store weekly hours for employees

Assume the weekly hours for all employees are stored in two-dimensional array. Each row records emaployee's seven-day workhours with seven columns.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd