Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9 global variables (p1,p2,p3,p4,p5,p6,p7,p8,p9). You need to update and access these global variables. Running displayBoard() should print out the 3*3 board with 3 rows and

9 global variables (p1,p2,p3,p4,p5,p6,p7,p8,p9). You need to update and access these global variables.

Running displayBoard() should print out the 3*3 board with 3 rows and 3 columns and the characters. Running the code after displayBoard() function for the first time should be like:

------- |A|B|C| ------- |D|E|F| ------- |G|H|I| -------

This is the displayBoard() function, which you shouldnot modify

void displayBoard(){ //Don't edit this function cout << endl << "------- " << "|" << p1 << "|" << p2 << "|" << p3 << "| " << "------- " << "|" << p4 << "|" << p5 << "|" << p6 << "| " << "------- " << "|" << p7 << "|" << p8 << "|" << p9 << "| " << "------- " << endl; }

Problem 1

Modify the function 'IsAdjacent' and leave 'problem1' intact:

Given the row and column indices of two cells, return true if they are adjacent (up-down, left-right). Otherwise return false.

Example:

Enter which problem to run: 1 Please enter the row index of the first cell. 1 Please enter the column index of the first cell. 2 Please enter the row index of the second cell. 2 Please enter the column index of the second cell. 2 These two cells are adjacent. Done.

Problem 2

Read in two pairs of row and column indices. If these two cells are adjacent (up-down, left-right), set their values as 'X'. Otherwise, do nothing. Then 'main' function will display the table later. Hint: Consider creating a function that set a cell's value as 'X'. You may also want to use the IsAdjacent() function that you created in problem 1.

Example:

Enter which problem to run: 2 Please enter the row index of the first cell. 2 Please enter the column index of the first cell. 1 Please enter the row index of the second cell. 3 Please enter the column index of the second cell. 1 ------- |A|B|C| ------- |X|E|F| ------- |X|H|I| ------- Done.

Problem 3

Read in three pairs of row and column indices. If these three cells are in the same row or column, set all their values as 'X'. Then 'main' function will display the table later. It may save you some effort if you can call the function that you likely created in problem 2 to set a cell's value to be 'X'.

Example:

Enter which problem to run: 3 Please enter the row index of the first cell. 2 Please enter the column index of the first cell. 1 Please enter the row index of the second cell. 2 Please enter the column index of the second cell. 2 Please enter the row index of the third cell. 2 Please enter the column index of the third cell. 3 ------- |A|B|C| ------- |X|X|X| ------- |G|H|I| ------- Done.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696