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

Write in C++ 2) Write a function that generates 2 random numbers between 3 and 1

ID: 3586681 • Letter: W

Question

Write in C++

2) 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. (4 pts) 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. (8 pts) 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.

2d. (1 pt) print out the matrix with the 5 x’s.

Explanation / Answer

#include <cstdlib>

#include <iostream>

using namespace std;

int main()

{

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<<" ";

}

  

}

Output:

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