C++ Programming Code
Description
C++ source file name: Memory.cpp
File name must be Memory.cpp
Write a program that plays a memory game with cards containing upper-case letters. The cards are laid out in a 4×4 grid with row and column indices from 0 to 3, as follows (the left diagram with the dollar signs represent the back of the card, the right diagram represents the front of the card. Note that the letters on the cards should be randomly generated from uppercase A-Z each time the game is played from the start): Download Sample program)
0 1 2 3 |
0 1 2 3 |
Note that each letter is represented exactly twice in the right diagram. The objective of the game is to find as many matching pairs as possible.
Each round of gameplay should do the following:
- Print the board. Previously matched cards should show the matched letters.
- Ask the player if theyd like to Find a match (F) or Quit (Q)
- If the player chooses Find, ask for the two cards in row, column format. Make sure that the cards are not the same card(e.g., player chooses card 1,1 and 1,1) and that neither card has already been matched. If either of these cases is true, then prompt the player to choose new cards in row, column format.
- After each choice, tell the player how many points they have. They get a point for every matching pair of cards.
- Print the players final number of points if they choose to Quit (Q).
If there are no cards left to play (all matches have been found) the player wins and the game should print their final points and end. See the sample outputs for more details on gameplay.
Required Functions:
You code must have at least the following two functions. The parameters passed can be different than what is shown below. You may use any other functions you wish:
<strong>void print_board(char in_board[][BOARD_SIZE]);</strong>
This function prints the current board to the screen with matched cards flipped to show their letter and unmatched cards unflipped.
<strong>void fill_board(char in_board[][BOARD_SIZE]);</strong>
This function fills the board with randomly selected uppercase letters in the range A-Z. Note that each letter generated must appear exactly twice on the board.
Your program’s output must match the output below as exactly as possible.
Scenario 1: One Round, Cards Match
(the matched cards stay flipped to their letter for the rest of the game):
Welcome to Memory Game! Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | $ | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>2,3</strong>Pick second card (row, column): <strong>1,3</strong>Cards match! You get a point!Your current points: 1Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | A-----------------2 | $ | $ | $ | A-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>Q</strong>Your total points: 1 Goodbye!
Scenario 2: One Round, Cards Dont Match
(the chosen cards are flipped to their letter after the non-match is announced):
Welcome to Memory Game!Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | $ | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>2,2</strong>Pick second card (row, column): <strong>1,3</strong>Cards do not match! Try again!Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | X-----------------2 | $ | $ | B | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>Q</strong>Your total points: 0 Goodbye!
Scenario 3: Multiple Rounds, Some Matches, Some Non-Matches:
(matched cards stay flipped to their letter, but non-matched go back to the $ after theyre shown):
Welcome to Memory Game!Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | $ | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>3,1</strong>Pick second card (row, column): <strong>2,2</strong>Cards match! You get a point!Your current points: 1Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | W | $-----------------3 | $ | W | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>0,2</strong>Pick second card (row, column): <strong>1,1</strong>Cards do not match! Try again!Here's the board: 0 1 2 30 | $ | $ | K | $-----------------1 | $ | Q | $ | $-----------------2 | $ | $ | W | $-----------------3 | $ | W | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>3,2</strong>Pick second card (row, column): <strong>2,3</strong>Cards do not match! Try again!Here's the board: 0 1 2 30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | W | X-----------------3 | $ | W | P | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>Q</strong>Your total points: 1Goodbye!
Submissions will be screened for plagiarism and other academically dishonest practices so you MUST do entirely your own work. You may help each other to understand and mathematically grasp the problems, but all submitted work must be unique and original. Please submit your assignment by the due date to the Assignment 3 location in Canvas.
Note: There are MANY solutions to this assignment online. Using these solutions too heavily, like copying and pasting parts or entire code solutions, is also considered Plagiarism.
Get your college paper done by experts
Do my question How much will it cost?Place an order in 3 easy steps. Takes less than 5 mins.
Leave a Reply
Want to join the discussion?Feel free to contribute!