At my course we are getting tasks that always start with filling a random matrix size nxm with random numbers.
I want to create(a library?, a class?) some structure so than any time I want to generate a matrix A I would need just to input the desired size nxm.
In other words, change all this code for something like #include <myrandommatrixgenerator>
.
int n, m;
cout << "Enter number of rows (n): ";
cin >> n;
cout << "Enter number of columns (m): ";
cin >> m;
//matrix b with random numbers
srand(time(NULL));
int max = 9, min = -9;
int *b = new int[n*m];
for (int i = 0; i<n; i++)
{
for (int j = 0; j<m; j++)
{
b[i*m + j] = min + ((rand() % max) + 1);
}
}
//print matrix b
cout << "\nMatrix b:" << endl;
for (int i = 0; i<n; i++)
{
for (int j = 0; j<m; j++)
{
cout << setw(5) << b[i*m + j];
}
cout << endl;
}
I do not have a broad overview of the possibilities with C++, so what is the structure that allow me to do that?