How to pass two-dimensional array as an argument?

前端 未结 6 905
萌比男神i
萌比男神i 2020-12-14 23:47

My Matrx class is defined as

class Matrx
{
 double A[50][50];
 int m,n;
public:
 Matrx(void);
 Matrx(int a, int b)
 {
  m=a;
  n=b;
 }
 Matrx o         


        
6条回答
  •  独厮守ぢ
    2020-12-15 00:42

    Thanks to all of you people...you were really helping...I have found myself a new definition of the class and the function definition for the matrix that fitted my need. I need you r comment on it...Below is the example of the class declaration..

    #include
    #include"stdafx.h"
    using namespace std;  
    const int M=100; const int N=100;  
    class Matrix  
    {  
        double A[M][N];  
        int m,n;  
    public:  
        Matrix(void);  
        Matrix(int a, int b)  
        {  
            m=a;  
            n=b;  
            for(int i=0;i

    and then the function implementation

    #include "stdafx.h"
    #include "Matrix.h"
    
    Matrix::Matrix(void)  
    {  
    }  
    
    Matrix Matrix::operator *(Matrix b)  
    {  
     Matrix c(m,m);  
     if(n!=b.m)  
     {  
        HWND hndOwner(0);   
        MessageBoxW(hndOwner,L"Multiplication not possible row and column does not match",L"Error",NULL);  
        Matrix errMat(1,0);  
        double er[1][1]={0}; errMat.readMatrix((double *)er);  
        return errMat;  
     }  
    for(int i=0;i< m;i++)  
    {  
    for(int k=0;k< m;k++)  
    {  
    c.A[i][k]=0;  
    for(int j=0;j< n;j++)  
    {  
    c.A[i][k] = c.A[i][k]+(A[i][j] * b.A[j][k]) ;  
    }  
    }  
    }  
    return c;  
    }  
    Matrix Matrix::operator +(Matrix b)  
    {  
        Matrix c(m,n);  
        if((n!=b.n)||(m!=b.m))  
     {  
        HWND hndOwner(0);   
        MessageBoxW(hndOwner,L"Addition not possible row and column does not match",L"Error",NULL);  
        Matrix errMat(1,0);  
        double er[1][1]={0}; errMat.readMatrix((double *)er);  
        return errMat;  
     }  
        for(int i=0;i

    The simple codes in the above are working well till now...if you have any suggestion for the improvement please suggest..

提交回复
热议问题