Matrix - operator* // multiplication of two matrices /...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// This file contains the definition of the class Matrix / #include "Matrix.h" # // ----------------------------------------------------------------------- default constructor // a default matrix is an identity matrix / Matrix::Matrix(void) { M for (int x = 0; x < 4; x++) for (int y = 0; y < 4; y++) { if (x == y) m[x][y] = 1.0; else m[x][y] = 0.0; } } // ----------------------------------------------------------------------- copy constructor c for (int x = 0; x < 4; x++) f for (int y = 0; y < 4; y++) f m[x][y] = mat.m[x][y]; m } // ----------------------------------------------------------------------- destructor d Matrix::~Matrix (void) {} M // ----------------------------------------------------------------------- assignment operator a Matrix& return (*this); r for (int x = 0; x < 4; x++) f for (int y = 0; y < 4; y++) f m[x][y] = rhs.m[x][y]; m return (*this); } // -----------------------------------------------------------------------
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: operator* // multiplication of two matrices / Matrix Matrix::operator* (const Matrix&amp; mat) const { Matrix product; p for (int y = 0; y &lt; 4; y++) for (int x = 0; x &lt; 4; x++) { double sum = 0.0; d for (int j = 0; j &lt; 4; j++) sum += m[x][j] * mat.m[j][y]; product.m[x][y] = sum; p } return (product); } // ----------------------------------------------------------------------- operator/ // division by a scalar / Matrix Matrix::operator/ (const double d) { for (int x = 0; x &lt; 4; x++) f for (int y = 0; y &lt; 4; y++) f m[x][y] = m[x][y] / d; m return (*this); } // ----------------------------------------------------------------------- set_identity // set matrix to the identity matrix / void v Matrix::set_identity(void) { for (int x = 0; x &lt; 4; x++) for (int y = 0; y &lt; 4; y++) { if (x == y) m[x][y] = 1.0; else m[x][y] = 0.0; } }...
View Full Document

Page1 / 2

Matrix - operator* // multiplication of two matrices /...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online