#include<iostream>
#include<vector>
#include<time.h>
template<const size_t R, const size_t C>
class Matrix
{
public:
using row_type = int[C];
private: // attributes
int m_data[R][C];
public: // construction/assignment
Matrix ();
Matrix (const Matrix& source);
Matrix (Matrix&& source);
Matrix& operator= (const Matrix<R,C>& source);
Matrix& operator= (Matrix<R,C>&& source);
~Matrix () {}
public: // accessors
row_type& row (const size_t index) { return m_data[index]; }
const row_type& row (const size_t index) const { return m_data[index]; }
row_type& operator[] (const size_t index) { return m_data[index]; }
const row_type& operator[] (const size_t index) const { return m_data[index]; }
size_t size() const { return R * C; }
size_t rows() const { return R; }
size_t cols() const { return C; }
public: // operations
Matrix<R,C>& operator+= (const Matrix<R,C>&);
};
template<const size_t R, const size_t C>
Matrix<R,C>::Matrix()
{
for (size_t row=0; row<R; ++row)
for (size_t col=0; col<C; ++col)
m_data[row][col] = 0;
}
template<const size_t R, const size_t C>
Matrix<R,C>::Matrix(const Matrix<R,C>& source)
{
for (size_t row=0; row<R; ++row)
for (size_t col=0; col<C; ++col)
m_data[row][col] = source.m_data[row][col];
}
template<const size_t R, const size_t C>
Matrix<R,C>::Matrix(Matrix<R,C>&& source)
{
for (size_t row=0; row<R; ++row)
for (size_t col=0; col<C; ++col)
m_data[row][col] = std::move (source.m_data[row][col]);
}
template<const size_t R, const size_t C>
Matrix<R,C>& Matrix<R,C>::operator= (const Matrix<R,C>& source)
{
for (size_t row=0; row<R; ++row)
for (size_t col=0; col<C; ++col)
m_data[row][col] = source.m_data[row][col];
return *this;
}
template<const size_t R, const size_t C>
Matrix<R,C>& Matrix<R,C>::operator= (Matrix<R,C>&& source)
{
for (size_t row=0; row<R; ++row)
for (size_t col=0; col<C; ++col)
m_data[row][col] = std::move (source.m_data[row][col]);
return *this;
}
template<const size_t R, const size_t C>
Matrix<R,C>& Matrix<R,C>::operator+= (const Matrix<R,C>& rhs)
{
for (size_t row=0; row<R; ++row)
for (size_t col=0; col<C; ++col)
m_data[row][col] += rhs.m_data[row][col];
return *this;
}
template<const size_t R, const size_t C>
Matrix<R,C> operator+ (const Matrix<R,C>& lhs, const Matrix<R,C>& rhs)
{
Matrix<R,C> sum (lhs);
return sum += rhs;
}
template<const size_t R, const size_t C>
std::ostream& operator<< (std::ostream& os, const Matrix<R,C>& m)
{
for (size_t row=0; row<R; ++row)
{
for (size_t col=0; col<C; ++col)
{
std::cout << m[row][col] << '\t';
}
std::cout << std::endl;
}
return os;
}
int main()
{
srand ((unsigned)time(nullptr));
const size_t rows = 3;
const size_t cols = 3;
Matrix<rows, cols> a, b, c;
for (size_t row=0; row<rows; ++row)
{
for (size_t col=0; col<cols; ++col)
{
a[row][col] = rand() % 10;
b[row][col] = rand() % 10;
}
}
std::cout << "Matrix a:\n\n" << a << '\n' << std::endl;
std::cout << "Matrix b:\n\n" << b << '\n' << std::endl;
std::cout << "Matrix a + b:\n\n" << a + b << '\n' << std::endl;
}
#include<
write a program to multily 3*3 matrix.
http://www.assignmentsclub.com/
how to write a program for matrix multiplication in microprocesspr
Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.
for (i=0; i<IMAX; i++) for (j=0; j<JMAX; j++) c[i,j] = a[i,j] + b[i,j];
A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.
Yes, do write. That's what you always have to do when you have got a homework-program.
You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.
bgfygfrhjyuyhh
This is a directive, not a question.
matrix