Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/vector.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

329 changes: 329 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Catch
Submodule Catch updated from 153176 to ae5ee2
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# vector
Linear space element representation
[![Build status](https://ci.appveyor.com/api/projects/status/nc058q7m0wtg7of3/branch/solomon?svg=true)](https://ci.appveyor.com/project/ElenaVinogradova/vector/branch/solomon)
[![Build Status](https://travis-ci.org/ElenaVinogradova/vector.svg?branch=solomon)](https://travis-ci.org/ElenaVinogradova/vector)
41 changes: 21 additions & 20 deletions include/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,49 @@

class Vector {
public:
const static unsigned long n = 3;
const static unsigned long n = 3;

Vector();
Vector();

explicit Vector(double);
explicit Vector(double);

Vector(const Vector &);
Vector(const Vector &);

Vector &operator=(const Vector &);
Vector &operator=(const Vector &);

double operator[](unsigned long i) const;
double operator[](unsigned long i) const;

double &operator[](unsigned long i);
double &operator[](unsigned long i);

Vector &operator+=(const Vector &);
Vector &operator+=(const Vector &);

Vector &operator-=(const Vector &);
Vector &operator-=(const Vector &);

Vector &operator*=(double);
Vector &operator*=(double);

Vector &operator/=(double);
Vector &operator/=(double);

friend bool operator==(const Vector &, const Vector &);
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 &, const Vector &);
friend Vector operator-(const Vector &, const Vector &);

friend Vector operator*(const Vector &, double);
friend Vector operator*(const Vector &, double);

friend Vector operator*(double, const Vector &);
friend Vector operator*(double, const Vector &);

friend Vector operator/(const Vector &, double);
friend Vector operator/(const Vector &, double);

friend double operator^(const Vector &, const Vector &);
friend double operator^(const Vector &, const Vector &);

Vector operator-() const;
Vector operator-() const;

private:
double coords_[n];
double coords_[n];
}; // class Vector

bool operator!=(const Vector &, const Vector &);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему убрали оператор != ?


#endif // VECTOR_H

107 changes: 107 additions & 0 deletions src/vector.cpp
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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Vector(op1) += op2;

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Vector(op1) *= -1;

return Vector(*this) *= -1;
}

bool operator!=(const Vector &op1, const Vector &op2) {
return !(op1 == op2);

}