Please find the code below:;
#include <iostream>
#include <stdlib.h>
using namespace std;
void displayArray(char array[][4]); //function to display
array
bool gameFinish(char array[][4]); //check for game finish
int main()
{
int array[4][4]; //array of size 4
char arrayStar[4][4]; //array of size 4 for display
*
char digits[] = {'0', '1', '2', '3', '4', '5', '6',
'7', '8', '9' }; //convert int to char
int i=0,j=0;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
array[i][j]=0;
arrayStar[i][j]='*'; //initialize both array
}
}
int row=0,col=0; //rand row
bool insert = true; //rand col
for(i=1;i<=8;i++){ //for 1 to 8
insert= true; //initialize
variable
while(insert){
row =
rand()%4; //generate rand of 4
col =
rand()%4;
if(array[row][col]==0){ //if data is zero at rand position put
number there
insert = false;
}
}
array[row][col] = i; //putting
number
insert = true; //again same step
for second pair
while(insert){
row =
rand()%4;
col =
rand()%4;
if(array[row][col]==0){
insert = false;
}
}
array[row][col] = i;
}
displayArray(arrayStar); //display * array
int choiceRow1,choiceCol1,choiceRow2,choiceCol2;
do{
bool inputFlag= true;
do{
cout<<"Enter row(1 to 4) or column ( 1 to 4) position of the
pair";
cin>>choiceRow1>>choiceCol1;
if(choiceRow1<1 || choiceRow1>4 || choiceCol1<1 ||
choiceCol1>4 ){
cout<<"Invalid
position."<<endl;
}else
if(arrayStar[choiceRow1-1][choiceCol1-1] !='*'){
cout<<"Card at this position
already faced up. Select position again."<<endl;
}else{
inputFlag = false;
}
}while(inputFlag); //validate until
valid value
arrayStar[choiceRow1-1][choiceCol1-1] =
digits[array[choiceRow1-1][choiceCol1-1]]; //replace star array by
array value that is generated randomly
displayArray(arrayStar);
inputFlag = true;
do{
cout<<"Enter row(1 to 4) or column ( 1 to 4) position of the
pair";
cin>>choiceRow2>>choiceCol2;
if(choiceRow2<1 || choiceRow2>4 || choiceCol2<1 ||
choiceCol2>4 ){
cout<<"Invalid
position."<<endl;
}else
if(arrayStar[choiceRow2-1][choiceCol2-1] !='*'){
cout<<"Card at this position
already faced up. Select position again."<<endl;
}else{
inputFlag = false;
}
}while(inputFlag); //validate until
valid value
arrayStar[choiceRow2-1][choiceCol2-1] =
digits[array[choiceRow2-1][choiceCol2-1]];//replace star array by
array value that is generated randomly
displayArray(arrayStar);
if(array[choiceRow1-1][choiceCol1-1]!=array[choiceRow2-1][choiceCol2-1]){//if
not match print and replace again to *
cout<<"pair did not match!
select again"<<endl;
arrayStar[choiceRow1-1][choiceCol1-1] ='*';
arrayStar[choiceRow2-1][choiceCol2-1] ='*';
displayArray(arrayStar);
}else{ //else pair match
cout<<"pair
match"<<endl;
displayArray(arrayStar);
}
}while(!gameFinish(arrayStar));//do until game finish
return 0;
}
void displayArray(char array[][4]){//display array
int i,j;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
cout<<array[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl;
}
bool gameFinish(char array[][4]){ //check for game finish
int i,j;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(array[i][j]=='*'){
return
false;
}
}
cout<<endl;
}
return true;
cout<<endl;
}
output:
![E Console CPP_Workspace.exe [C/C++ Application] C:\Users Mohammad Shahrukh\Desktop\c_language_workspaceleclipse c\CP Choi ceg](http://img.homeworklib.com/images/e9c17816-ea12-4606-bd0b-e6b20100adf6.png?x-oss-process=image/resize,w_560)

Answer in basic C++ this is for a intro class no adavanced stuff past iostream, strings,ctime,fun...