Download presentation
Presentation is loading. Please wait.
Published byTerence Freeman Modified over 8 years ago
1
Problem Session Working in pairs of two, solve the following problem...
2
Problem We’ve seen how to derive a Matrix from vector. 123 456 789 then the transpose of that matrix is as follows: If a matrix is as follows: 147 258 369 Intuitively, the transpose operation interchanges the rows and columns of a matrix. Write a function member Matrix::Transpose() that returns the transpose of the Matrix receiving the message.
3
Coding: Interface // Matrix.h // Directives have been omitted... typedef vector Row; class Matrix : public vector { public: Matrix(); Matrix(int rows, int columns); int Rows() const; int Columns() const; Matrix operator+(const Matrix & mat2); Matrix Transpose() const; void Read(istream & in); void Print(ostream & out) const; friend istream & operator>>(istream & in, Matrix & mat); friend ostream & operator<<(ostream & out, const Matrix & mat); //...
4
Coding: Definition // Matrix.cpp //... Matrix Matrix::Transpose() const // I’m m-by-n { Matrix result(myColumns, myRows); // it’s n-by-m for (int r = 0; r < myRows; r++) // for row r for (int c = 0; c < myColumns; c++) // for col c result[c][r] = (*this)[r][c]; // set result return result; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.