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

The grid must look like the example above. The size vary based on user input. La

ID: 3721086 • Letter: T

Question

The grid must look like the example above. The size vary based on user input.

Language: c++

Size requirement: product of row x col must be between 16 and 64 and be even Enter rows: 3 Enter columns: 4 Size requirement: product of row x col must be between 16 and 64 and be even Enter rows: 7 Enter columns: 3 Size requirement: product of row x col must be between 16 and 64 and be even Enter rows: 5 Enter columns: 4 llowing 30 seconds per pair ou will have 5 minutes and seconds to find the 10 pairs. Let's play 1 23 4 5 6 78 9 10 11 12 13 14 15 16 17 18 19 20 Enter first slot to view:

Explanation / Answer

#include <iostream>
#include <vector>
#include <time.h>
#include <math.h>

using namespace std;

void createMatrix(vector<vector<char>> &mat, int row, int col){
char ip[(row*col)/2];
int cnt_ip[(row*col)/2] = {0};

for (int k=0; k<(row*col)/2; k++){
ip[k] = 65 + ( std::rand() % ( 96 - 65 + 1 ) );
}

for(int i=0; i<row; i++){
mat.push_back(vector<char>());
for(int j=0; j<col; j++){
int k = std::rand() % ((row*col)/2);
if(cnt_ip[k] < 2){
mat[i].push_back(ip[k]);
cnt_ip[k] ++;
}
else{
k++;
while(cnt_ip[k] == 2){
k = (k+1)%((row*col)/2);
}
mat[i].push_back(ip[k]);
cnt_ip[k] ++;
}
}
}
}

void matchpairs(vector<vector<char>> mat, int rows, int cols){

int row1,col1,row2,col2;
int p,q,r;
for(int i=0; i<mat.size(); i++){
for(int j=0; j<mat[i].size(); j++){
cout<<(i*rows)+j<<" ";
}
cout<<" ";
}

for(int i=0; i<mat.size(); i++){
for(int j=0; j<mat[i].size(); j++){
cout<<mat[i][j]<<" ";
}
cout<<" ";
}


while(1){
cout<<"Enter slot to view: ";
cin>>p>>q;
col1 = p%rows;
row1 = (p-col1)/rows;
col2 = q%rows;
row2 = (q-col2)/rows;
if(mat[row1][col1] == mat[row2][col2])
cout<<p<<" and "<<q<<" are match"<<" ";
else
cout<<p<<" and "<<q<<" are not match"<<" ";
cout<<"Matching Done?:"<<" ";
cin>>r;
if(r == 1)
break;
else
continue;
}
}

int main(){
srand(time(NULL));
int k;
int rows;
int cols;

while(1){
cout<<"Enter Your Choice: ";
cout<<"1. Find Matches 2. Exit ";
cin>>k;
if(k == 1){
cout<<"Size Requirement:Product of row X col must be between 16 and 64 and be even ";
cout<<"Enter Rows: ";
cin>>rows;
cout<<"Enter Cols: ";
cin>>cols;

vector <vector<char> > matrix;

if(rows * cols >= 16 && rows * cols <= 64 && ((rows * cols) % 2 == 0)){
createMatrix(matrix, rows, cols);
matchpairs(matrix, rows, cols);
}
else
cout<<"Size Requirements not met !!!! ";
}
else if(k == 2){
break;
}
else
cout<<"Invalid Command !!!!! ";
}
return 0;
}