Question
Coding in C++ Please fix my code: This is an ADT Matrix program in c++, which allows the user to create a matrix of any
Coding in C++
Please fix my code:
This is an ADT Matrix program in c++, which allows the user to create a matrix of any size and store it into a slot. Then the user can take the matrices in these stored slots to perform addition, subtraction, or multiplication then store the matrix in another slot.
As you can see in the sample run.
[ 2 2 2 ] [ 4 4 4 ] [ 6 6 6 ]
[ 2 2 2 ] add [ 4 4 4 ] = [ 6 6 6 ]
[ 2 2 2] [ 4 4 4 ] [ 6 6 6 ]
or
[ 4 4 4 ] [ 2 2 2 ] [ 2 2 2 ]
[ 4 4 4 ] sub [ 2 2 2 ] = [ 2 2 2 ]
[ 4 4 4 ] [ 2 2 2 ] [ 2 2 2 ]
however
[ 4 4 4 ] [ 2 2 2 ] [ 24 24 24 ]
[ 4 4 4 ] mul [ 2 2 2 ] = [ 24 24 24 ]
[ 4 4 4 ] [ 2 2 2 ] [ 24 24 24 ]
the matrix should be 8 instead of 24. Please help me debug my multiple function.
// Here iss the code
#include
const int MAX_ROWS = 10; const int MAX_COLS = 10;
class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ostream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand); private: int values[MAX_ROWS][MAX_COLS]; int numRows; int numCols; }; MatrixType::MatrixType() { numRows = numCols = 0; } void MatrixType::MakeEmpty() { for(int i = 0; i = 1 && c >= 1) { numRows = r; numCols = c; } else cout = 0 && c = 0) values[r][c] = item; else cout
void new_matrix(int i, MatrixType * matrices, bool * add) { int r, c, temp; cout > r >> c; if(r > 0 && r 0 && c > temp; matrices[i].StoreItem(temp, j, k); } } matrices[i].Print(cout); } else cout = 0 && i "; cout //here is the sample run
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started