-
Notifications
You must be signed in to change notification settings - Fork 22
Solomon #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Solomon #3
Changes from all commits
31b22e3
ba50e5c
5a2c5e4
755e25d
694cb18
d4cd865
51cfa1c
7b8058a
5f2db23
33c066a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [submodule "Catch"] | ||
| path = Catch | ||
| url = https://github.com/philsquared/Catch.git | ||
| url = https://github.com/philsquared/Catch |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| # vector | ||
| Linear space element representation | ||
| [](https://ci.appveyor.com/project/ElenaVinogradova/vector/branch/solomon) | ||
| [](https://travis-ci.org/ElenaVinogradova/vector) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #include "vector.h" | ||
|
|
||
| Vector::Vector() { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] = 0; | ||
| } | ||
| } | ||
|
|
||
| Vector::Vector(double a) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] = a; | ||
| } | ||
| } | ||
|
|
||
| Vector::Vector(const Vector &op) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] = op.coords_[i]; | ||
| } | ||
| } | ||
|
|
||
| Vector &Vector::operator=(const Vector &op) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] = op.coords_[i]; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| double Vector::operator[](unsigned long i) const { | ||
| return coords_[i]; | ||
| } | ||
|
|
||
| double &Vector::operator[](unsigned long i) { | ||
| return coords_[i]; | ||
| } | ||
|
|
||
| Vector &Vector::operator+=(const Vector &op) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] += op.coords_[i]; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
|
|
||
| Vector &Vector::operator-=(const Vector &op) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] -= op.coords_[i]; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| Vector &Vector::operator*=(double a) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] *= a; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| Vector &Vector::operator/=(double a) { | ||
| for (unsigned int i = 0; i < n; ++i) { | ||
| coords_[i] /= a; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| bool operator==(const Vector &op1, const Vector &op2) { | ||
| for (unsigned int i = 0; i < Vector::n; i++) { | ||
| if (op1.coords_[i] != op2.coords_[i]) { | ||
| return false; } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| Vector operator+(const Vector &op1, const Vector &op2) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return Vector(op1)+=op2; | ||
| } | ||
|
|
||
| Vector operator-(const Vector &op1, const Vector &op2) { | ||
| return Vector(op1)-=op2; | ||
| } | ||
|
|
||
| Vector operator*(const Vector &op, double a) { | ||
| return Vector(op) *= a; | ||
| } | ||
| Vector operator*(double a, const Vector &op){ | ||
| return Vector(op) *= a; | ||
| } | ||
|
|
||
| Vector operator/(const Vector &op1, double a) { | ||
| return Vector(op1) /= a; | ||
| } | ||
|
|
||
| double operator^(const Vector &op1, const Vector &op2) { | ||
| double res = 0; | ||
| for (unsigned int i = 0; i < Vector::n; ++i) { | ||
| res += op1.coords_[i] * op2.coords_[i]; | ||
| } | ||
| return res; | ||
| } | ||
|
|
||
| Vector Vector::operator-() const { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return Vector(*this) *= -1; | ||
| } | ||
|
|
||
| bool operator!=(const Vector &op1, const Vector &op2) { | ||
| return !(op1 == op2); | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему убрали оператор != ?