Created
July 1, 2017 18:53
-
-
Save ArtyomLazyan/a47649d62644a393e5da17c71fedae0b to your computer and use it in GitHub Desktop.
CreateMatric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
class MatricFactory | |
{ | |
public: | |
int** createArray(int row, int col, int initial = 0) | |
{ | |
int **arr = new int* [row]; | |
for (int i = 0; i < row; i++) | |
{ | |
arr[i] = new int [col]; | |
} | |
for (int i = 0; i < row; i++) | |
{ | |
for (int j = 0; j < col; j++) | |
{ | |
arr[i][j] = initial; | |
} | |
} | |
return arr; | |
} | |
void showArray(int *arr[], int row, int col) | |
{ | |
for (int i = 0; i < row; i++) | |
{ | |
for (int j = 0; j < col; j++) | |
{ | |
std::cout << arr[i][j] << " "; | |
} | |
std::cout << std::endl; | |
} | |
} | |
void cleanMemory(int *arr[], int row) | |
{ | |
for (int i = 0; i < row; i++) | |
delete [] arr[i]; | |
delete [] arr; | |
} | |
}; | |
int main() | |
{ | |
int row, col, initial; | |
std::cout << "Set row col size: "; | |
std::cin >> row >> col; | |
std::cout << "Set initial: "; | |
std::cin >> initial; | |
/* create instance of class Matric factory */ | |
MatricFactory matricFactory; | |
int **matric = matricFactory.createArray(row, col, initial); | |
matricFactory.showArray(matric, row, col); | |
matricFactory.cleanMemory(matric, row); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment