51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
/*
|
|
Äèíàìè÷åñêè âûäåëèòü ìàòðèöó 4õ4 òèïà int. Èíèöèàëèçèðîâàòü åå ïñåâäîñëó÷àéíûìè
|
|
÷èñëàìè ÷åðåç ôóíêöèþ rand. Âûâåñòè íà ýêðàí. Ðàçáåéòå âàøó ïðîãðàììó íà
|
|
ôóíêöèè êîòîðûå âûçûâàþòñÿ èç main.
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
void PrintArray(int**, const size_t);
|
|
void FillRandArray(int**, const size_t);
|
|
|
|
int Task_2()
|
|
{
|
|
std::cout << "\t\tTask #2" << std::endl;
|
|
|
|
const size_t SIZE = 4U;
|
|
int** aaInts = new (std::nothrow) int* [SIZE];
|
|
if (aaInts != nullptr && SIZE > 0)
|
|
{
|
|
for (size_t i = 0; i < SIZE; i++)
|
|
{
|
|
aaInts[i] = new int[SIZE];
|
|
if (aaInts[i] == nullptr)
|
|
{
|
|
std::cerr << "Something wrong with memory allocation in Task #2.\n";
|
|
return -1;
|
|
}
|
|
}
|
|
std::cout << "Memory allocation is successful." << std::endl;
|
|
FillRandArray(aaInts, SIZE);
|
|
PrintArray(aaInts, SIZE);
|
|
}
|
|
else
|
|
{
|
|
std::cerr << "Something wrong with memory allocation in Task #2.\n";
|
|
return -1;
|
|
}
|
|
|
|
std::cout << "Allocated memory deletion ...\n";
|
|
for (size_t i = 0; i < SIZE; i++)
|
|
{
|
|
delete[] aaInts[i];
|
|
}
|
|
delete[] aaInts;
|
|
|
|
std::cout << "________________________________________________\n\n";
|
|
system("pause");
|
|
system("cls");
|
|
return 0;
|
|
}
|