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

Using a pair of 2 dimensional character arrays, you are going tocreate a game of

ID: 3617664 • Letter: U

Question

Using a pair of 2 dimensional character arrays, you are going tocreate a game of memory for the user to play. The grid shouldbe a 3 x 6 grid that looks like:

   1 2 3 4 5 6

1 X X X X X X

2 X X X X X X

3 X X X X X X

Another array should hold the pairs of values and should becreated by random. The values can be any symbol you would liketo use I.E. % # & ! @ ~

#include<iostream.h>
#include <stdlib.h>
#include <conio.h>

//define so cot , dong
const int COL = 3;
const int ROW = 6;


/**
Main function
Chuong tring se run function nay khi hoat dong
*/
void main()
{

//clear screen.
clrscr();


randomize();

// Khai bao bien
int i, j, count ;
// create array two dememsion
char data[COL][ROW];
char datasave[COL][ROW] ;


//asign data (%, #, &, !, @, ~ ) vao array
char keys[6];
  keys[0] = '%';
  keys[1] = '#';
  keys[2] = '&';
  keys[3] = '!';
  keys[4] = '@';
  keys[5] = '~';

// delete emtyarray
for(i=0; i<COL ; i ++ )
{

  for(j=0; j<ROW; j ++ )
  {
   data[i][j] = NULL ;
  }
}

// Create randomvalues to array
for(i=0; i<9 ; i ++ )
{
  char tmp = keys[ int(rand()%6) ] ;
  data[int((i)/ROW)][int((i)%ROW)] =tmp ;
  data[int((9+i)/ROW)][int((9+i)%ROW)] = tmp;
}


//random vi tri
int index1, index2 ;
for(i=0; i<9 ; i ++ )
{
  index1 = rand()%18 ;
  index2 = rand()%18 ;
  //cout<<" " <<index1 <<","<<index2;
  if(index1 != index2)
  {
   //swap: doi vi tri 2 so
   char tmp =data[int((index1)/ROW)][int((index1)%ROW)] ;
   data[int((index1)/ROW)][int((index1)%ROW)] =data[int((index2)/ROW)][int((index2)%ROW)];
   data[int((index2)/ROW)][int((index2)%ROW)] =tmp;
  }
}


// save data
for(i=0; i<COL ; i ++ )
{

  for(j=0; j<ROW; j ++ )
  {
   datasave[i][j] = data[i][j];
  }
}


// Print array
// cac gia tri tu 1 den 18
count = 0 ;
for(i=0; i<COL ; i ++ )
{
  for(j=0; j <ROW; j ++ )
  {
   count ++ ;
   cout << " " << data[i][j];//count;
  }
  cout << " ";
}

// tao 2 bien luu vitri lua chon
int number1, number2 ;
char value1, value2 ;

int check1 = 0,check2=0;
//loop cho den khi choi xong
do
{
  cout <<"Input number 1:";
  cin >> number1 ;
  cout <<"Input number 2:";
  cin >> number2 ;

  // lay gia tritron array ra compare
  value1 =data[int((number1-1)/ROW)][int((number1-1)%ROW)] ;
  value2 =data[int((number2-1)/ROW)][int((number2-1)%ROW)] ;

  //neu dung(giong nhau) bien kiem tra tang len 1
  if(value1 == value2)
   check1 ++ ;

  cout <<" Values are: " << value1 << "&" << value2<< " " ;


}while(0);// (check1 + check2) <= 1 );


// wating press any key.
getch();
return ;
}

Explanation / Answer

please rate - thanks you didn't mention error checking, so there is none. you had your rows and columns reversed #include #include #include //define so cot , dong const int COL = 6; const int ROW = 3; /** Main function Chuong tring se run function nay khi hoat dong */ int main() { //clear screen. //clrscr(); system("CLS"); // randomize(); srand(time(0)); // Khai bao bien int i, j, k, count=0,tmp; // create array two dememsion char data[ROW][COL]; char xxx[ROW][COL]; int used[9]={0}; //asign data (%, #, &, !, @, ~ ) vao array char keys[9]={'%','#','&','!','@','~','^','$','+'}; // create x array for(i=0; i
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