//TwoDimension.h
#ifndef _TWO_
#define _TWO_
#include <iostream>
int** AllocateBuffer(int xDimension, int yDimension);
void ReleaseBuffer(int** myArray, int xDimension);
void InitializeMatrix(int** myArray,int xDimension,int yDimension);
void DisplayMatrix(int** myArray, int xDimension, int yDimension);
#endif
//TwoDimension.cpp
#include "TwoDimension.h"
using namespace std;
int** AllocateBuffer(int xDimension, int yDimension)
{
int** temp = new int* [xDimension];
for (int i = 0;i < xDimension; ++i)
{
temp[i] = new int [yDimension];
}
return temp;
}
void ReleaseBuffer(int** myArray, int xDimension)
{
for (int i = 0; i < xDimension ; ++i)
{
delete [] myArray[i];
myArray[i] = NULL;
}
delete [] myArray;
myArray = NULL;
}
void InitializeMatrix(int** myArray, int xDimension, int yDimension)
{
for (int i = 0; i < xDimension; ++i)
for (int j = 0; j < yDimension; ++j)
myArray[i][j] = ((i==j)||(j==yDimension-1))?1:0;
}
void DisplayMatrix(int** myArray, int xDimension, int yDimension)
{
for (int i = 0; i < xDimension; ++i)
{
for (int j = 0; j < yDimension; ++j)
cout<< myArray[i][j];
cout<<endl;
}
}
//test.cpp
#include "TwoDimension.h"
using namespace std;
void main()
{
int** matrix;
int L;
cout<<"input L:"<<endl;
cin>>L;
int xDimension = 2*L;
int yDimension = 2*L + 1;
matrix = AllocateBuffer(xDimension,yDimension);
InitializeMatrix(matrix,xDimension,yDimension);
DisplayMatrix(matrix,xDimension,yDimension);
ReleaseBuffer(matrix,xDimension);
}