Skip to content

Implementation of the matrix library in the OOP approach

License

Notifications You must be signed in to change notification settings

sheritsh/s21_matrix_oop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

s21_matrix+

Implementation of the s21_matrix_oop.h library.

The russian version of the task can be found here.

Contents

  1. About project
  2. How to build a lib
  3. Matrix operations
  4. Technical specifications
  5. Unit tests

s21_matrix

About project

This project was carried out according to the curriculum of School 21.

As part of this project, I familiarized myself with the syntax and features of C++. I practiced the object-oriented programming (OOP) approach and learned about the Rule of Five, move semantics, and references. I maintained the approach of allocating all memory at once for the entire matrix from the previous project. Additionally, all functions were covered using the Google Test Framework.

How to build a lib

Please open the ./src directory and execute the make command in the terminal to build s21_matrix_oop.a library.

Matrix operations

Operation Description Exceptional situations
bool EqMatrix(const S21Matrix& other) Checks matrices for equality with each other
void SumMatrix(const S21Matrix& other) Adds the second matrix to the current one different matrix dimensions
void SubMatrix(const S21Matrix& other) Subtracts another matrix from the current one different matrix dimensions
void MulNumber(const double num) Multiplies the current matrix by a number
void MulMatrix(const S21Matrix& other) Multiplies the current matrix by the second matrix the number of columns of the first matrix is not equal to the number of rows of the second matrix
S21Matrix Transpose() Creates a new transposed matrix from the current one and returns it
S21Matrix CalcComplements() Calculates the algebraic addition matrix of the current one and returns it the matrix is not square
double Determinant() Calculates and returns the determinant of the current matrix the matrix is not square
S21Matrix InverseMatrix() Calculates and returns the inverse matrix matrix determinant is 0

Apart from those operations, you also need to implement constructors and destructors:

Method Description
S21Matrix() A basic constructor that initialises a matrix of some predefined dimension
S21Matrix(int rows, int cols) Parametrized constructor with number of rows and columns
S21Matrix(const S21Matrix& other) Copy constructor
S21Matrix(S21Matrix&& other) Move constructor
~S21Matrix() Destructor

And you also need to overload the following operators, partly corresponding to the operations above:

Operator Description Exceptional situations
+ Addition of two matrices different matrix dimensions
- Subtraction of one matrix from another different matrix dimensions
* Matrix multiplication and matrix multiplication by a number the number of columns of the first matrix does not equal the number of rows of the second matrix
== Checks for matrices equality (EqMatrix)
= Assignment of values from one matrix to another one
+= Addition assignment (SumMatrix) different matrix dimensions
-= Difference assignment (SubMatrix) different matrix dimensions
*= Multiplication assignment (MulMatrix/MulNumber) the number of columns of the first matrix does not equal the number of rows of the second matrix
(int i, int j) Indexation by matrix elements (row, column) index is outside the matrix

Technical specifications

  • The program must be developed in C++ language of C++17 standard using gcc compiler
  • The program code must be located in the src folder
  • When writing code it is necessary to follow the Google style
  • Implement the matrix as an S21Matrix class
  • Use only the matrix_, rows_ and cols_ fields as private.
  • Implement the access to private fields rows_ and cols_ via accessor and mutator. If the matrix increases in size, it is filled with zeros. If it decreases in size, the excess is simply discarded.
  • Make it as a static library (with s21_matrix_oop.h header file)
  • Implement the operations described above
  • Overload the operators according to the table in the chapter above
  • Prepare full coverage of library functions code with unit-tests using the GTest library
  • Provide a Makefile for building the library and tests (with targets all, clean, test, s21_matrix_oop.a)

Test results

Using the Google Test Framework, all functions, including error handling, were covered with tests. This ensures comprehensive test coverage for the code and guarantees proper program behavior, including correct error handling. Excellent work in adopting such an approach!

test_result

About

Implementation of the matrix library in the OOP approach

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages