update test cases and format code

This commit is contained in:
Ilya Grigorev
2024-10-09 14:09:48 +05:00
parent a41c15f3ee
commit 60bd99e570
8 changed files with 485 additions and 363 deletions
+33 -30
View File
@@ -6,12 +6,12 @@
#include <vector>
/**
* Vector is a class to represent
* a column vector with n rows.
*/
* Vector is a class to represent
* a column vector with n rows.
*/
class Vector {
class Vector
{
protected:
// Number of rows in vector
int rows;
@@ -19,39 +19,41 @@ protected:
int columns;
// Matrix representation as vector of vectors of integers
std::vector<double> vector;
public:
Vector(int n);
Vector(const Vector& other);
Vector(const Vector &other);
Vector(std::initializer_list<double>);
/* Getter for the number of rows */
int size() const;
double& operator[](int row);
double &operator[](int row);
Vector& operator=(const Vector& other);
Vector &operator=(const Vector &other);
Vector operator+(Vector& other);
Vector operator+(Vector &other);
Vector operator-(Vector& other);
Vector operator-(Vector &other);
/* Input operator reads element of vector */
friend std::istream& operator>>(std::istream& cin, Vector& vectorObj);
friend std::istream &operator>>(std::istream &cin, Vector &vectorObj);
/* Output operator prints elements of the vector
* in a row separated with a space (no space at the end of the line)
*/
friend std::ostream& operator<<(std::ostream& cout, Vector& vectorObj);
* in a row separated with a space (no space at the end of the line)
*/
friend std::ostream &operator<<(std::ostream &cout, Vector &vectorObj);
};
/**
* Class Matrix represents
* a matrix of size n x m
* of type integer.
*/
class Matrix {
* Class Matrix represents
* a matrix of size n x m
* of type integer.
*/
class Matrix
{
protected:
// Number of rows in matrix
int rows;
@@ -59,10 +61,11 @@ protected:
int columns;
// Matrix representation as vector of vectors of integers
std::vector<Vector> matrix;
public:
Matrix(int n, int m);
Matrix(const Matrix& other);
Matrix(const Matrix &other);
Matrix(std::initializer_list<std::vector<double>>);
@@ -72,15 +75,15 @@ public:
/* Getter for the number of columns */
int getColumns() const;
Vector& operator[](int row);
Vector &operator[](int row);
Matrix& operator=(const Matrix& other);
Matrix &operator=(const Matrix &other);
Matrix operator+(Matrix& other) const;
Matrix operator+(Matrix &other) const;
Matrix operator-(Matrix& other) const;
Matrix operator-(Matrix &other) const;
Matrix operator*(Matrix& other) const;
Matrix operator*(Matrix &other) const;
/* Matrix-Vector multiplication */
Vector operator*(Vector other) const;
@@ -89,12 +92,12 @@ public:
Matrix transpose() const;
/* Input operator reads element of matrix row by row */
friend std::istream& operator>>(std::istream& cin, Matrix& matrixObj);
friend std::istream &operator>>(std::istream &cin, Matrix &matrixObj);
/* Output operator prints elements of the matrix
* row by row separated with a space (no space at the end of each line)
*/
friend std::ostream& operator<<(std::ostream& cout, Matrix& matrixObj);
* row by row separated with a space (no space at the end of each line)
*/
friend std::ostream &operator<<(std::ostream &cout, Matrix &matrixObj);
};
#endif // TOOLS_MATRIX_H
#endif // TOOLS_MATRIX_H