Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. (Memory Game A common memory matching game played by young children is to sta

ID: 3606212 • Letter: 3

Question

3. (Memory Game A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six cards in the deck, two might be labeled "1", two might be labeled "2 and two might be labeled "3". The cards are shuffied and placed face down on the table. The player then selects two cards that are face down, turns them face up, and if they match they are left face up. If the two cards do not match they are returned to their original position face down. The game continues in this fashion until all cards are face up or the user chooses not to continue. Write a program that plays the memory matching game. Use sixteen cards that are laid out in a 4x4 square and are labeled with pairs of numbers from 1 to 8, respectively. Your program should allow the player to specify the cards that the user would like to select through a coordinate system. For example, in the following layout: 3 All ot the cards are face down except for the pair 6 which has been located at coordinates (1,1) and (2,3). Hint: Use a 2D array for the initial arrangement of cards Lint carda [LENCT) CLENCTE (1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8):) and another 2D array that indicates if a card is face up or face down (bool faceup[LENCTH] ILENGTE] (0)). Write a function that "shuffies" the cards in the array by repeatedly (say 10000 times) selecting two cards at random and swapping them. See the sample output. Use another function sbowBoardt show output board nter the size of the board 2 or 4:4 ind all the watching pairs on the boand. nter an x and y position of the Ast card to flip: 33 nter an x and y position of tho card to fup: 2 3 have s pairs to reveal. To continue enter (Y or y): m 1 234 could only find e matching pairs in 1 iterations need to look for exercises to boost your menory

Explanation / Answer

#include "stdafx.h"

#include "stdlib.h"

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

char comma;

int r1, c1, r2, c2, cards[4][4];

srand((unsigned)time(NULL));

loop:

//fill board

for (int r=0; r<4; r++)

{

for (int c=0; c<4; c++)

{

cards[r][c]=rand()%8+1;

}

}

//display board

cout<<" 1 2 3 4 ";

cout<<" ";

for (int i=0; i<=8; i++)

{

cout<<"-";

}

cout<<endl;

for (int r=0; r<4; r++)

{

cout<<r+1<<" | ";

for (int c=0; c<4; c++)

{

cout<<"* ";

}

cout<<endl;

}

cout<<endl;

cout<<"Please insert the first card row and column seperated by a comma. ";

cin>>r1>>comma>>c1;

cout<<"Please insert the second card row and column seperated by a comma. ";

cin>>r2>>comma>>c2;

//fix

r1--;

c1--;

r2--;

c2--;

//reveal

cout<<" 1 2 3 4 ";

cout<<" ";

for (int i=0; i<=8; i++)

{

cout<<"-";

}

cout<<endl;

for (int r=0; r<4; r++)

{

cout<<r+1<<" | ";

for (int c=0; c<4; c++)

{

if ((r==r1)&&(c==c1))

{

cout<<cards[r][c]<<" ";

}

else if((r==r2)&&(c==c2))

{

cout<<cards[r][c]<<" ";

}

else

{

cout<<"* ";

}

}

cout<<endl;

}

cout<<"Enter 1 to play again. Enter 0 to quit: ";

cin>>r1;

if (r1 == 1)

{

system("CLS");

goto loop;

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote