Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include "Matrix.h" Matrix::Matrix(){ //Do Nothing; } Matrix::Matrix(int row, int column, vector
coefficient){ this->row = row; this->column = column; this->coefficient = coefficient; } void Matrix::setMatrix(int row, int column, vector
coefficient){ this->row = row; this->column = column; this->coefficient = coefficient; } vector
Matrix::getCoefficient() const { return this->coefficient; } int Matrix::getRow() const { return this->row; } int Matrix::getColumn() const { return this->column; } void Matrix::operator()(){ auto it = this->coefficient.begin(); for(int i=0; i
row; i++){ for(int j=0; j
column; j++){ cout << fixed << setprecision(2) << setw(8) << *it++; } cout << endl; } } bool Matrix::isAddable(const Matrix& matrix){ if(this->row == matrix.getRow() && this->column == matrix.getColumn()) return true; return false; } bool Matrix::isSubstractable(const Matrix& matrix){ if(this->row == matrix.getRow() && this->column == matrix.getColumn()) return true; return false; } bool Matrix::isMultipliable(const Matrix& matrix){ if(this->column == matrix.getRow()) return true; return false; } Matrix Matrix::operator+(const Matrix& matrix){ Matrix res; vector
result; //transform(this->coefficient.begin(), this->coefficient.end(), matrix.coefficient.begin(), result.begin(), ::plus
()); auto it1 = this->coefficient.begin(); auto it2 = matrix.coefficient.begin(); for( ;it1 != this->coefficient.end(); it1++, it2++){ double num = *it1 + *it2; result.push_back(num); } res.setMatrix(this->row, this->column, result); return res; } Matrix Matrix::operator-(const Matrix& matrix){ Matrix res; vector
result; auto it1 = this->coefficient.begin(); auto it2 = matrix.coefficient.begin(); for( ;it1 != this->coefficient.end(); it1++, it2++){ double num = *it1 - *it2; result.push_back(num); } res.setMatrix(this->row, this->column, result); return res; } Matrix Matrix::operator*(const Matrix& matrix){ Matrix res; vector
result; auto it1 = this->coefficient.begin(); auto it2 = matrix.coefficient.begin(); for(int i=0; i
row; i++){ for(int j=0; j
column; k++){ sum += *(it1 + i*this->column+k) * *(it2 + k*matrix.column+j); } result.push_back(sum); } } res.setMatrix(this->row, matrix.column, result); return res; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)