#include <iostream>
using std::cout;
// using std::cin;
// using std::string;
using std::endl;
void FillArray(int** const arr, const int rows, const int cols)
{
for (short i = 0; i < rows; i++)
{
arr[i] = new int[cols];
for (short j = 0; j < cols; j++)
{
arr[i][j] = 1 + rand() % 20;
}
}
}
void ShowArray(int** arr, const int rows, const int cols)
{
cout << "rows: " << rows << " cols: " << cols << endl;
// cout << arr[0][1] << endl;
for (short i = 0; i < rows; i++)
{
for (short j = 0; j < cols; j++)
{
cout << arr[i][j] << '\t';
}
cout << endl;
}
}
void CopyArray(int** fArr, int** const SArr, const int rows, const int colsS)
{
for (short i = 0; i < rows; i++)
{
delete[] fArr[i];
}
delete[] fArr;
fArr = new int*[rows];
for (short i = 0; i < rows; i++)
{
fArr[i] = new int[colsS];
}
for (short i = 0; i < rows; i++)
{
for (short j = 0; j < colsS; j++)
{
fArr[i][j] = SArr[i][j];
// cout << FArr[i][j] << '\t';
}
// cout << endl;
}
cout << fArr[0][0] << endl;
}
int main()
{
srand(time(0));
const short rows = 3, cols1 = 3, cols2 = 5;
int **fArr = new int*[rows];
int **sArr = new int*[rows];
FillArray(fArr, rows, cols1);
FillArray(sArr, rows, cols2);
cout << "First array:" << endl;
ShowArray(fArr, rows, cols1);
cout << endl << "Second array:" << endl;
ShowArray(sArr, rows, cols2);
CopyArray(fArr, sArr, rows, cols2);
cout << endl << "First array:" << endl;
ShowArray(fArr, rows, cols2);
cout << endl << "Second array:" << endl;
ShowArray(sArr, rows, cols2);
for (short i = 0; i < rows; i++)
{
delete[] fArr[i];
delete[] sArr[i];
}
delete[] fArr;
delete[] sArr;
}