1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
DataSource.cpp:
#include "DataSource.h"
#include "Memory.h"
DataSource :: DataSource()
{
numberOfRow = 4;
numberOfColumn = 4;
int mat[4][4] = { { 2, 4, 1, -3 },
{ -1, -2, 2, 4 },
{ 4, 2, -3, 5 },
{ 5, -4, -3, 1 } };
// For a large data file, it's essential to put the data elements from the file to heap due to filtering.
// Once the filtered data elements is transfered to Matrix array, delete all the data element from dataElement array and free the space.
dataElement = allocateData2DbyNew(numberOfRow, numberOfColumn);
for (int row = 0; row < numberOfRow; row++)
{
for (int col = 0; col < numberOfColumn; col++)
{
dataElement[row][col] = mat[row][col];
}
}
}
DataSource :: ~DataSource()
{
destroyData2DbyDelete(dataElement, numberOfRow, numberOfColumn);
dataElement = nullptr;
}
|
Matrix.cpp:
#include "DataSource.h"
#include "Matrix.h"
#include "Memory.h"
#include <iostream>
Matrix :: Matrix()
{
DataSource *dataObj = new DataSource;
this->matrixElement = allocateData2DbyNew(dataObj->numberOfRow, dataObj->numberOfColumn);
//..Copy the data from Data Source to Matrix array. Filtarazation might necessary before copying.
for (int row = 0; row < dataObj->numberOfRow; row++)
{
for (int col = 0; col < dataObj->numberOfColumn; col++)
{
this->matrixElement[row][col] = dataObj->dataElement[row][col];
std::cout << this->matrixElement[row][col] << " ";
}
std::cout << std::endl;
}
delete dataObj;
dataObj = nullptr;
}
Matrix :: ~Matrix()
{
}
|