update test cases and format code
This commit is contained in:
+33
-30
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user