Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There is lab07_functions.h Using C++,thanks. #ifndef MATRIX_TYPE #define MATRIX_TYPE #include using std::string; #include using std::vector; /* very convenient. If you want to change the type
There is lab07_functions.h Using C++,thanks. |
#ifndef MATRIX_TYPE #define MATRIX_TYPE #includeThe Problem We are going to work on 2D vectors 2D vector as a matrix You remember matrices, don't you? We are going to do some simple manipulation ofa matrix, namely: adding two matrices and multiplying a matrix by a scalar. You watched the 2D vector video, right? RIGHT??? Matrix A matrix is a 2-dimensional (rows and columns) data structure. It has a shape indicated by the number of rows and the number of columns. Though I suppose a matrix could have uneven sized rows, this doesn't usually happen in practice so a matrix is always rectangular, potentially square (based on its shape)using std::string; #include using std::vector; /* very convenient. If you want to change the type stored in the matrix, you only have to change the single template type in matrix_row */ using matrix_row = vector ; using matrix = vector ; /* nicely print a matrix. Should have row/column alignment converts it to a string (doesn't print to cout!!!) uses width to space elements (setw). Default is 3 */ string matrix_to_str(const matrix &m1, size_t width=3); /* true if the two matrices have the same shape false otherwise */ bool same_size(matrix &m1, matrix &m2); /* matrices must not be empty and must be the same shape: - if true, return a new matrix that adds m1+m2 - if false, return an empty matrix (no elements) */ matrix add(matrix &m1, matrix &m2); /* matrix must not be empty: - if true, multiply T scalar value by m - if false, return empty matrix (no elements) */ matrix scalar_multiply(matrix &m, long val); #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started