From 39a946a8fd6de855d1654469cf76f699feeea142 Mon Sep 17 00:00:00 2001 From: Alexalexlxl Date: Sat, 23 Apr 2016 02:55:54 +0300 Subject: [PATCH 1/4] change --- CMakeLists.txt | 2 - include/vector.h | 201 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 160 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1fedc0..b32f693 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,6 @@ include_directories(include) enable_testing() -set(SOURCES src/vector.cpp) - add_executable(test_vector tests/test_vector.cpp ${SOURCES}) add_test(NAME ${PROJECT_NAME} COMMAND test_vector) \ No newline at end of file diff --git a/include/vector.h b/include/vector.h index 222a4fe..a8e6b32 100644 --- a/include/vector.h +++ b/include/vector.h @@ -2,49 +2,168 @@ #define VECTOR_H class Vector { -public: - const static unsigned long n = 3; - - Vector(); - - explicit Vector(double); - - Vector(const Vector &); - - Vector &operator=(const Vector &); - - double operator[](unsigned long i) const; - - double &operator[](unsigned long i); - - Vector &operator+=(const Vector &); - - Vector &operator-=(const Vector &); - - Vector &operator*=(double); - - Vector &operator/=(double); - - friend bool operator==(const Vector &, const Vector &); - - friend Vector operator+(const Vector &, const Vector &); - - friend Vector operator-(const Vector &, const Vector &); - - friend Vector operator*(const Vector &, double); - - friend Vector operator*(double, const Vector &); - - friend Vector operator/(const Vector &, double); - - friend double operator^(const Vector &, const Vector &); - - Vector operator-() const; +public: + const static unsigned long n = 3; + +Vector() +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] = 0; + } +}; + +explicit Vector(double number) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] = number; + } +}; + +Vector(const Vector &other) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] = other.coords_[i]; + } +}; + +Vector &operator=(const Vector &other) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] = other.coords_[i]; + } + return *this; +}; + +double operator[](unsigned long i) const +{ + return coords_[i]; +}; + +double &operator[](unsigned long i) +{ + return coords_[i]; +}; + +Vector &operator+=(const Vector &other) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] += other.coords_[i]; + } + return *this; +}; + +Vector &operator-=(const Vector &other) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] -= other.coords_[i]; + } + return *this; +}; + +Vector &operator*=(double number) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] *= number; + } + return *this; +}; + +Vector &operator/=(double number) +{ + for (unsigned long i = 0; i < n; i++) + { + coords_[i] /= number; + } + return *this; +}; + +friend bool operator==(const Vector &lhs, const Vector &rhs) +{ + for (unsigned long i = 0; i < n; ++i) + { + if (lhs.coords_[i] != rhs.coords_[i]) + { + return false; + } + } + return true; +}; + +friend Vector operator+(const Vector &our, const Vector &other) +{ + Vector Vector_return(our); + return Vector_return += other; +}; + +friend Vector operator-(const Vector &our, const Vector &other) +{ + Vector Vector_return(our); + return Vector_return -= other; +}; + +friend Vector operator*(const Vector &our, double number) +{ + Vector Vector_return(our); + return Vector_return *= number; +}; + +friend Vector operator*(double number, const Vector &our) +{ + Vector Vector_return(our); + return Vector_return *= number; +}; + +friend Vector operator/(const Vector &our, double number) +{ + Vector Vector_return(our); + return Vector_return /= number; +}; + +friend std::ostream &operator<<(std::ostream &stream, const Vector &v) +{ + for (unsigned long i = 0; i < n; i++) + { + stream< Date: Sat, 23 Apr 2016 03:03:15 +0300 Subject: [PATCH 2/4] badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f536447..a2a84b8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # vector Linear space element representation +[![Build status](https://ci.appveyor.com/api/projects/status/5hqdicdrxuhkt958/branch/ivanov?svg=true)](https://ci.appveyor.com/project/Alexalexlxl/vector/branch/ivanov) \ No newline at end of file From a0834c27023c737ac7fb33ffc3b0910f3a710d52 Mon Sep 17 00:00:00 2001 From: Alexalexlxl Date: Sat, 23 Apr 2016 03:06:48 +0300 Subject: [PATCH 3/4] badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2a84b8..acba542 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # vector Linear space element representation -[![Build status](https://ci.appveyor.com/api/projects/status/5hqdicdrxuhkt958/branch/ivanov?svg=true)](https://ci.appveyor.com/project/Alexalexlxl/vector/branch/ivanov) \ No newline at end of file +[![Build status](https://ci.appveyor.com/api/projects/status/5hqdicdrxuhkt958/branch/ivanov?svg=true)](https://ci.appveyor.com/project/Alexalexlxl/vector/branch/ivanov) From ae10d16259b1014b12febd4fabe41de7f7e07aaf Mon Sep 17 00:00:00 2001 From: Alexalexlxl Date: Sat, 23 Apr 2016 03:08:19 +0300 Subject: [PATCH 4/4] badge1 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index acba542..c760d73 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # vector Linear space element representation [![Build status](https://ci.appveyor.com/api/projects/status/5hqdicdrxuhkt958/branch/ivanov?svg=true)](https://ci.appveyor.com/project/Alexalexlxl/vector/branch/ivanov) +[![Build Status](https://travis-ci.org/Alexalexlxl/vector.svg?branch=ivanov)](https://travis-ci.org/Alexalexlxl/vector) \ No newline at end of file