Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please help me out.

C++
#include <iostream>
#include <cstring>

using namespace std;

struct matrixType{
    int matDimension;
    int matValues[10][10];
};

class MatrixADT{

    private:
        matrixType resultMatrix;

    public:

       //Member function declarations
  
        void intializeResultMatrix(int);
matrixType add(matrixType, matrixType);
        matrixType subtract(matrixType,matrixType);
        matrixType multiply(matrixType,matrixType);
        void printResult();
};

//Member functions of Matrix class to be defined here
matrixType MatrixADT::add(matrixType M1, matrixType M2){
//Insert code here
}

matrixType MatrixADT::subtract(matrixType M1, matrixType M2){
//Insert code here
}

matrixType MatrixADT::multiply(matrixType M1, matrixType M2){
//Insert code here
}

void MatrixADT::intializeResultMatrix(int dim){

}

int main(){

    MatrixADT maX;
    matrixType M1, M2;
    char op;
    int dim;

/*Enter your code here to accept two input matrices as instances of class Matrix and perform the operations using member functions, display the result matrix using member function*/


maX.printResult();
            
}


void MatrixADT::printResult(){

    int i,j;
    for (i=0;i<resultmatrix.matdimension;i++){>
        for (j=0; j<resultmatrix.matdimension-1;j++){>
            cout<<resultMatrix.matValues[i][j]<<" ";
        }
       cout <<resultMatrix.matValues[i][j]<<"\n";
    }
    cout <<"Done";
}
Posted
Updated 7-Apr-14 22:39pm
v2
Comments
Richard MacCutchan 8-Apr-14 4:40am    
Help you out with what?
Rage 8-Apr-14 4:51am    
With his homework, e.g. replace the comments stating "Insert code here" with code.
PLZZZ.URGT.

1 solution

Quote:
struct matrixType{
int matDimension;
int matValues[10][10];
};
What is the purpose of the matDimension member, since you have hard-wired dimensions (namely 10x10)?

As first attempt, you could implement your Matrix class, this way:
C++
#include <iostream>
#include <iomanip>
using namespace std;
class Matrix
{
  static const int N = 10;
  int m[N][N];

public:
  Matrix();
  //... other ctors here
  Matrix & add(const Matrix & other);
  //... other operations here
  void show();
};

Matrix::Matrix()
{
  for (int i=0; i<N; ++i)
    for (int j=0; j<N; ++j)
      m[i][j] = 0;
}
//... other ctors here
Matrix & Matrix::add(const Matrix & other)
{
  for (int i=0; i<N; ++i)
    for (int j=0; j<N; ++j)
      m[i][j] += other.m[i][j];

  return *this;
}
 //... other operations here
void Matrix::show()
{
  for (int i=0; i<N; ++i)
  {
    for (int j=0; j<N; ++j)
      cout << m[i][j] << " ";
    cout << endl;
  }
}

int main()
{
  Matrix m;
  m.show();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900