Code:
////////////////////////////////////////////////////////////////////////////////
class Matrix {
private:
int M_R; // Number of rows
public:
//Matrix(); // Constructor
~Matrix(){}; // Destructor
int M_C; // Number of columns is only public for debugging
int MxN[5][5]; // Cell values (m*n)
// Methods
void Input_MxN(void); // Values for matrix cells
void Size(void); // Size of matrix
void Ma_comp(void);
void add(const Matrix& B,const Matrix& A);
}; //Matrix
////////////////////////////////////////////////////////////////////////////////
void Matrix::Input_MxN(void){
Size();
if (M_C > 5){
cout << "no";
}else{
cout << "M_C:" << M_C;
}
cout << endl << "MC:" << M_C << endl;
getch();
} // Input MxN
////////////////////////////////////////////////////////////////////////////////
void Matrix::Size(void) {
clrscr();
cout << "number of columns:";
cin >> M_C;
clrscr();
cout << "number of rows:";
cin >> M_R;
} // Size
////////////////////////////////////////////////////////////////////////////////
void Matrix::Ma_comp(){
Matrix A;
A.Input_MxN();
Matrix B;
B.Input_MxN();
clrscr();
int x = (A.M_C-B.M_C);
cout << x;
getch();
}
////////////////////////////////////////////////////////////////////////////////
void Matrix::add(const Matrix& B,const Matrix& A){
for (int i=0; i < M_R+1; i++){
for (int j=0; j < M_C+1; j++){
cout << "Matrix A:" << A.MxN[i][j] << endl;
cout << "Matrix B:" << B.MxN[i][j] << endl;
MxN[i][j]=(A.MxN[i][j]+B.MxN[i][j]);
cout << "Matrix C:" << A.MxN[i][j] << endl;
}
}
getch();
}
////////////////////////////////////////////////////////////////////////////////
int main(void){
Matrix C;
Matrix A;
A.MxN[5][5]=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
A.Input_MxN();
Matrix B;
B.MxN[5][5]=(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
B.Input_MxN();
clrscr();
cout << "A:" << A.Matrix::M_C << endl;
cout << "B:" << B.Matrix::M_C << endl;
getch();
C.add(B,A);
} // Main
/
AS you can see Im adding the values of MxN of objects A and B to MxN of object C.