Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ Welcome to the memory game! Look away from the board and have a helper enter r to randomize the board until they have

Using C++

Welcome to the memory game! Look away from the board and have a helper enter r to randomize the board until they have a random board that they like. Then you glance at it and try to imprint it in your mind and look away. Your helper will then select a single piece to be flipped by choosing its row and column. The changed board is then displayed. You then must try to guess which one it was. Enter x to exit the program. 1 2 3 4 5 6 - - - - - - - - A | X X O O X O | A B | X O O O X X | B C | X X O O O X | C D | O X X X X X | D E | X O X X O O | E F | X O X X O O | F - - - - - - - - Enter r to randomize to board, or row and column to change a value -> r 1 2 3 4 5 6 - - - - - - - - A | O X O X X O | A B | O O X O X X | B C | O O X O O O | C D | O X O O O O | D E | O O X O X X | E F | X X O O O X | F - - - - - - - - Enter r to randomize to board, or row and column to change a value -> r 1 2 3 4 5 6 - - - - - - - - A | O X X O X O | A B | O O O X O O | B C | O X O X X O | C D | O O O X O O | D E | O O O X X X | E F | X X O X O O | F - - - - - - - - Enter r to randomize to board, or row and column to change a value -> e1 1 2 3 4 5 6 - - - - - - - - A | O X X O X O | A B | O O O X O O | B C | O X O X X O | C D | O O O X O O | D E | X O O X X X | E F | X X O X O O | F - - - - - - - - What piece do you think it was? -> e1 *** Congratulations, you did it! *** Thank you for playing. Exiting... Notes Your program must use 36 char variables named p0..p35 to represent the board. They must be used in printing the board and in being checked to validate parity. These board characters may be declared globally. The secret to this program is that there are an odd number of Xs in each row and column on the board. This is known as odd parity. When a single position is changed, then the corresponding row and column for that position now have an even number of Xs, thus giving away the position for this single position that is changed. You may not use arrays, or strings, or any other method to circumvent the need to handle fundamentally using the 36 variables throughout your program. Failure to follow this constraint will result in a 20 point deduction. (Hint: Think about how you would write the program if you were using arrays. Consider how you might instead use a function in each location where otherwise you would use an array. If you figure this out, please do not give it away on Piazza.) Input for 'x' to exit, 'r' to randomize, or row letter should be accepted as either upper or lower case. The row letter and column number should be accepted when entered right next to each other as shown in the example above, or separated by a space. Note that your program needs to be able to handle either a single input ('r' or 'x') or two characters of input (e.g. "C5"). To do this you should have a cin statement to read the first character. Then check it. Only if it is not 'r' or 'x' then read a second character using cin. After the helper enters two-digit input to select which position to change, your program should print 25 blank lines, so that the original board scrolls off the top of the screen and is no longer visible. To initialize the board variables use rand() to generate a random number. You should #include at the top of your program for rand() to work. Consider how you would use rand() to initialize board variable p0. You would generate a random number and then check to see if it is even or odd (using the mod operator). If the random number is even, set the board variable p0 to 'O'. If the random number is odd, set that board variable p0 to 'X'. Repeat this for each board variable, starting with p0 and ending with p35. Only after this is done should you display the board for the first time. When you display the board you can use cout with a string literal (e.g. cout << " 1 2 3 4 5 6 7 "; ) to display the parts around the edges, but for the interior section you should be printing the variables (e.g. cout << p0 << " " << p1 ...) that contain the previously set 'X' or 'O' values. I suggest generating and displaying the board like this should be the first part of the program that you write. In the final stage where you ask the user "What piece do you think it was?" your program does not need to handle 'x' to exit.

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

Students also viewed these Databases questions

Question

3. Describe the communicative power of group affiliations

Answered: 1 week ago