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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <stdlib.h>
#include <malloc.h>
#include <iostream>
#include <fstream>
using namespace std;
void allocateMatrix(int **& A, int row, int col)
{
int i;
A = new int*[row];
for (i=1; i<=col; i++)
A[i] = new int[col];
}
void ReadData(int **& A, int row, int col) // read data from file
{
int i,j;
ifstream REL1;
REL1.open ("REL"); // open file for reading
for(i=1;i<=row;i++) // row loop
{
for(j=1;j<=col;j++) // column loop
{
REL1 >> A[i][j]; // read data into matrix
}
REL1.close(); // close the file
}
}
void Display(int **& A, int row, int col) // display matrix
{
int i,j;
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
cout << A[i][j] << "\t "; // display numbers
}
cout << endl;
}
}
void Cero(int **& A, int row, int col) // display matrix
{
int i,j;
for(i=1;i<=row;i++)
{
for(j=1;j<=col;j++)
{
A[i][j]=0;
}
}
}
int main()
{
int tm,rowR,colR,rowM,colM,**A,**B;
ifstream TM;
TM.open("TM");
TM >> tm;
TM.close();
rowR = rowM = colM = tm;
colR = 2;
allocateMatrix(A, rowM, colM);
allocateMatrix(B, rowR, colR);
Cero(A, rowM, colM);
//Display(A, rowM, colM);
ReadData(B ,rowR, colR);
Display(B, rowR, colR);
}
|