"matrix class in c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "matrix class in c++" answered properly. Developers are finding an appropriate answer about matrix class in c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like matrix class in c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on matrix class in c++.
matrix class in c++
template<class T>
class matrix{
size_t ROW,COL;
vector<vector<T>> mat;
public:
matrix(size_t N, size_t M, int populate = 0){
this->ROW = N;
this->COL = M;
this->mat = vector<vector<T>> (ROW,vector<T> (COL,populate));
}
matrix(size_t N, int populate = 0){
this->ROW = N;
this->COL = N;
this->mat = vector<vector<T>> (ROW,vector<T> (COL,populate));
}
void __init(){
for(int i = 0; i < ROW; ++i){
for(int j = 0; j < COL; ++j){
cin >> this->mat[i][j];
}
}
}
void __display(){
for(int i = 0; i < ROW; ++i){
for(int j = 0; j < COL; ++j){
cout << this->mat[i][j] << " ";
}
cout << "\n";
}
}
matrix<T> operator*(const matrix &rhs)const{
if(this->COL != rhs.ROW){
throw "MATRIX MULTIPLICATION CANNOT HAPPEN WITH THE GIVEN MATRICES"
}
matrix<T> result(this->ROW,rhs.COL);
for(int _i = 0; _i < this->ROW; _i++){
for(int _j = 0; _j < rhs.COL; _j++){
result[_i][_j] = 0;
for(int _k = 0; _k < this->COL; ++_k){
result[_i][_j]+=(this->mat[_i][_k]*rhs.mat[_k][_j]);
}
}
}
return result;
}
matrix<T> power(int n){
if(n == 0)return matrix<T>(this->ROW, this->COL,1);
if(n == 1)return *this;
matrix p = power(n/2);
p = p*p;
if(n%2)p = p*(*this);
return p;
}
};
All those coders who are working on the C++ based application and are stuck on matrix class in c++ can get a collection of related answers to their query. Programmers need to enter their query on matrix class in c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about matrix class in c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of matrix class in c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "matrix class in c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like matrix class in c++ resolved professionally and stay updated to the latest C++ updates.