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

2a. Write a function that generates 2 random numbers between 3 and 10 (not inclu

ID: 3587924 • Letter: 2

Question

2a. Write a function that generates 2 random numbers between 3 and 10 (not including 10). Change the two input parameters to those 2 random numbers. Create a new matrix, with the dimensions of those 2 numbers. Fill it with 0s. Return the address of the matrix. 2b.

2b. Write a function that takes the array and the input parameters and prints out the matrix so that it looks like a matrix, e.g., if the dimensions were 3,4, the printout would look like: 0 0 0 0 0 0 0 0 0 0 0 0

2c. Write a function that adds 5 x’s to the matrix in random location. (think bombs on a minesweeper board, or possibly really small battleships on a battleship board). Make sure that if there’s an x already in that place, you find another place to put the x.

This is the code I have in the main file but I need to recode it so that it is a function.

   int random_integer1 = rand()%10;

   int random_integer2 = rand()%10;

   int matrix[random_integer1][random_integer2];

       for(int i=0;i<random_integer1;i++) {

           for(int j=0;j<random_integer2;j++){

               matrix[i][j]=0;

           }

   }

   cout<<"Matrix values are ";

       for(int i=0;i<random_integer1;i++){

           for(int j=0;j<random_integer2;j++){

               cout<<" "<<matrix[i][j];

   }

   cout<<" ";

   }

   cout<<" After adding 5 to the Matrix values are ";

       for(int i=0;i<random_integer1;i++){

           for(int j=0;j<random_integer2;j++)

   {

               if(j%2==0)

                   matrix[i][j]=matrix[i][j]+5;

                       cout<<" "<<matrix[i][j];

   }

      

   cout<<" ";

   }

  

Explanation / Answer

int random_integer1 = rand()%6+4;
int random_integer2 = rand()%6+4;
int* Input_Matrix(int random_integer1,int random_integer2)
{
    int matrix[random_integer1][random_integer2];
    for(int i=0;i<random_integer1;i++)
   {
        for(int j=0;j<random_integer2;j++)
       {
            matrix[i][j]=0;
        }
    }
    return matrix;
}
void Show_Matrix(int &matrix)
{
   cout<<"Matrix values are ";
    for(int i=0;i<random_integer1;i++)
   {
        for(int j=0;j<random_integer2;j++)
       {
            cout<<" "<<matrix[i][j];
       }
    cout<<" ";
   }
}
void Add_in_Matrix(int &matrix)
{
   cout<<" After adding 5 to the Matrix values are ";
    for(int i=0;i<random_integer1;i++)
   {
        for(int j=0;j<random_integer2;j++)
        {  
            if(j%2==0)
            matrix[i][j]=matrix[i][j]+5;
            cout<<" "<<matrix[i][j];
       }
   cout<<" ";
    }
}

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