






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The code and explanations for various assignment and matrix operators in c++. Topics include self-assignment, matrix assignment, addition, and multiplication operators. The document also covers the use of pointers and arrays, as well as rules for programming and an introduction to classes and objects.
Typology: Exercises
1 / 38
This page cannot be seen from the preview
Don't miss anything!































Assignment Operator A = B
Assignment Operator ( A = B ) = C
Self Assignment
Class Matrix numRows = m.numRows ; numCols = m.numCols ; for ( int i = 0 ; i < numRows ; i ++ ) { for ( int j = 0 ; j < numCols ; j ++ ) { elements [ i ] [ j ] = m.elements [ i ] [ j ] ; } } } return * this ; }
Addition Operator
Class Matix Matrix Matrix :: operator + ( Matrix & m ) const { // Check for conformability if ( numRows == m.numRows && numCols == m.numCols ) { Matrix temp ( * this ) ; for ( int i = 0 ; i < numRows ; i ++ ) { for ( int j = 0 ; j < numCols ; j ++) { temp.elements [ i ] [ j ] += m.elements [ i ] [ j ] ; } } return temp ; } Matrix temp ( * this ) ; return temp ; } 8: Docsity.com
+= Operator
Class Matrix const Matrix & Matrix :: operator += ( Matrix & m ) {
Class Matrix Matrix Matrix :: operator + ( double d ) const { Matrix temp ( * this ) ; for ( int i = 0 ; i < numRows ; i ++ ) { for ( int j = 0 ; j < numCols ; j ++ ) { temp.elements [ i ] [ j ] += d ; } } return temp ; } Docsity.com
Operator**
Class Matrix Matrix Matrix :: operator * ( const Matrix & m ) { Matrix temp ( numRows , m.numCols ) ; if ( numCols == m.numRows ) { for ( int i = 0 ; i < numRows ; i ++ ) { for ( int j = 0 ; j < m.numCols ; j ++ ) { temp.elements [ i ] [ j ] = 0.0 ; for ( int k = 0 ; k < numCols ; k ++ ) { temp.elements [ i ] [ j ] += elements [ i ] [ k ] * m.elements [ k ] [ j ] ; } } } } return temp ; }
Matrix / d Check d = 0?
Extraction Operator << Insertion Operator