From 53b533c5ece20148f5740fd5dd0b4e7d3ec5eddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=9F=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D1=83=D0=BD=D0=BE=D0=B2?= Date: Thu, 5 May 2022 18:40:09 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=96=D0=B8=D0=B2=D0=BE=D1=82=D0=BD=D1=8B=D0=B5=20=E2=84=961?= =?UTF-8?q?=20=D0=B8=20=D0=96=D0=B8=D0=B2=D0=BE=D1=82=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- animals/animal.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++- animals/animal.h | 80 +++++++++++++++++++++++++++++++++-- 2 files changed, 177 insertions(+), 5 deletions(-) diff --git a/animals/animal.cpp b/animals/animal.cpp index 6745215..e2f8e07 100644 --- a/animals/animal.cpp +++ b/animals/animal.cpp @@ -2,6 +2,104 @@ using namespace std; -int main() { - return 0; +Animal::Animal(float _weight, int _age) { + weight = _weight; + age = _age; + } + +string Animal::about() const { + stringstream ss; + ss << "Weight: " << weight << " kg" << ", age: " << age << " years"; + return ss.str(); + } + +ostream& operator << (ostream &out, const Animal &animal) { + return out << animal.about(); +} + +Mammal::Mammal(float _weight, int _age, int _pregnancyLength) : Animal(_weight, _age) { + pregnancyLength = _pregnancyLength; + } + +string Mammal::about() const { + stringstream ss; + ss << Animal::about(); + ss << ", pregnancyLength: " << pregnancyLength << " days"; + return ss.str(); + } + +Reptile::Reptile(float _weight, int _age, float _eggHeight) : Animal(_weight, _age) { + eggHeight = _eggHeight; + } + +string Reptile::about() const { + stringstream ss; + ss << Animal::about(); + ss << ", eggHeight: " << eggHeight << " centimeters"; + return ss.str(); + } + +Cat::Cat(float _weight, int _age, int _pregnancyLength, float _vibrissaeLength) : Mammal(_weight, _age, _pregnancyLength) { + vibrissaeLength = _vibrissaeLength; + } + +string Cat::about() const { + stringstream ss; + ss << Mammal::about(); + ss << ", vibrissaeLength: " << vibrissaeLength << " centimeters"; + return ss.str(); + } + +Dog::Dog(float _weight, int _age, int _pregnancyLength, string _breed) : Mammal(_weight, _age, _pregnancyLength) { + breed = move(_breed); + } + +string Dog::about() const { + stringstream ss; + ss << Mammal::about(); + ss << ", breed: " << breed; + return ss.str(); + } + +Turtle::Turtle(float _weight, int _age, float _eggHeight, float _shellSize) : Reptile(_weight, 4, _eggHeight) { + shellSize = _shellSize; + } + +string Turtle::about() const { + stringstream ss; + ss << Reptile::about(); + ss << ", shellSize: " << shellSize << " meters"; + return ss.str(); + } + +Snake::Snake(float _weight, int _age, float _eggHeight, float _length) : Reptile(_weight, _age, _eggHeight) { + length = _length; + } + +string Snake::about() const { + stringstream ss; + ss << Reptile::about(); + ss << ", length: " << length << " meters"; + return ss.str(); + } + +int main() +{ + // tests: + Dog dog_1 = Dog(25, 4, 60, "Husky"); + Cat cat_1 = Cat(10, 8, 65, 7); + Turtle turtle_1 = Turtle(100, 2, 8, 2.35); + Snake python = Snake(50, 12, 0.38, 5); + + cout << "dog_1: " << dog_1.about() << endl; + cout << "cat_1: " << cat_1.about() << endl; + cout << "turtle_1: " << turtle_1.about() << endl; + cout << "python: " << python.about() << endl; + cout << "" << endl; + cout << "dog_1: " << dog_1 << endl; + cout << "cat_1: " << cat_1 << endl; + cout << "turtle_1: " << turtle_1 << endl; + cout << "python: " << python << endl; + + return 0; } \ No newline at end of file diff --git a/animals/animal.h b/animals/animal.h index 83a1944..342ab5a 100644 --- a/animals/animal.h +++ b/animals/animal.h @@ -1,18 +1,92 @@ #pragma once #include +#include +#include class Animal { +protected: + float weight; // kg + int age; // years + + Animal(float _weight, int _age); public: - float weight; // kg + virtual std::string about() const = 0; + + float get_weight() const { return weight; } + void set_weight(float _weight) { weight = _weight; } + + int get_age() const { return age; } + void set_age(int _age) { age = _age; } + + friend std::ostream& operator << (std::ostream &out, const Animal &animal); }; class Mammal : public Animal { +protected: + int pregnancyLength; // days + + Mammal(float _weight, int _age, int _pregnancyLength); +public: + std::string about() const override; + + int get_pregnancyLength() const { return pregnancyLength; } + void set_pregnancyLength(int _pregnancyLength) { pregnancyLength = _pregnancyLength; } +}; + +class Reptile : public Animal { +protected: + float eggHeight; // centimeters + + Reptile(float _weight, int _age, float _eggHeight); public: - float pregnancyDuration; // days + std::string about() const override; + + float get_eggHeight() const { return eggHeight; } + void set_eggHeight(float _eggHeight) { eggHeight = _eggHeight; } }; class Cat : public Mammal { +private: + float vibrissaeLength; // centimeters public: - float vibrissaLength; // meters + Cat(float _weight, int _age, int _pregnancyLength, float _vibrissaeLength); + + std::string about() const override; +}; + +class Dog : public Mammal { +private: + std::string breed; +public: + Dog(float _weight, int _age, int _pregnancyLength, std::string _breed); + + std::string about() const override; + + std::string get_breed() const { return breed; } + void set_breed(std::string _breed) { breed = _breed; } +}; + +class Turtle : public Reptile { +private: + float shellSize; // meters +public: + Turtle(float _weight, int _age, float _eggHeight, float _shellSize); + + std::string about() const override; + + float get_shellSize() const { return shellSize; } + void set_shellSize(float _shellSize) { shellSize = _shellSize; } +}; + +class Snake : public Reptile { +private: + float length; // meters +public: + Snake(float _weight, int _age, float _eggHeight, float _length); + + std::string about() const override; + + float get_length() const { return length; } + void set_length(float _length ) { length = _length; } }; From 57348ffa9b15220453f1dab4c9fb45229b76a7cf Mon Sep 17 00:00:00 2001 From: Dmitrii Piskunov Date: Fri, 27 May 2022 18:11:27 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electricity/electricity.cpp | 81 +++++++++++++++++++++++++++++++++---- electricity/electricity.h | 33 ++++++++++++++- memhacks/memhacks.cpp | 28 ++++++++++--- memhacks/memhacks.h | 14 +++++-- memhacks/newhacks.cpp | 46 ++++++++++++++++++++- memhacks/newhacks.h | 36 +++++++++++++++++ vectors/array.cpp | 19 ++++++--- vectors/array.h | 29 ++++++++----- vectors/vector.cpp | 37 ++++++++++------- vectors/vector.h | 22 +++++++++- 10 files changed, 296 insertions(+), 49 deletions(-) diff --git a/electricity/electricity.cpp b/electricity/electricity.cpp index 62da945..9004b4d 100644 --- a/electricity/electricity.cpp +++ b/electricity/electricity.cpp @@ -5,20 +5,37 @@ using namespace std; bool Object::isConnectedTo(const Object& other) const { - // TODO + for (int i = 0; i < getPoleCount(); ++i) { + auto pole = getPole(i); + if (pole != nullptr && pole->connectedObject == &other) + return true; + } return false; } bool Object::connect(const std::string& poleName, Object& other, const std::string& otherPoleName) { - // TODO - return false; + if (poleName == otherPoleName && &other == this) return false; + auto pole = getPole(poleName); + auto otherPole = (Pole*)(other.getPole(otherPoleName)); + if (otherPole == nullptr || otherPole == nullptr) return false; + pole->connectedObject = (Object*)(&other); + pole->connectedObjectPole = otherPoleName; + otherPole->connectedObject = this; + otherPole->connectedObjectPole = poleName; + return true; } bool Object::disconnect(const std::string& poleName) { - // TODO - return false; + auto pole = getPole(poleName); + if (pole->connectedObjectPole == "") + return false; + else { + pole->connectedObjectPole = ""; + pole->connectedObject = nullptr; + return true; + } } Switch::Switch(const std::string& name) @@ -39,17 +56,67 @@ const Pole* Switch::getPole(const string& name) const const Pole* Switch::getPole(size_t idx) const { - // TODO + return getPole("A" + to_string(idx + 1)); +} + +Lamp::Lamp(const string &name) + : Object(name) + , a1("A1") + , a2("A2") +{ +} + +const Pole *Lamp::getPole(const string &name) const { + if (name == a1.name) + return &a1; + if (name == a2.name) + return &a2; + return nullptr; +} + +const Pole *Lamp::getPole(size_t idx) const { + return getPole("A" + to_string(idx + 1)); +} + +Generator::Generator(const string &name) + : Object(name) + , a1("A1") + , a2("A2") + , a3("A3") +{ +} + +const Pole *Generator::getPole(const string &name) const { + if (name == a1.name) + return &a1; + if (name == a2.name) + return &a2; + if (name == a3.name) + return &a3; return nullptr; } +const Pole *Generator::getPole(size_t idx) const { + return getPole("A" + to_string(idx + 1)); +} + int main() { Switch sw, sw2; sw.connect("A2", sw2, "A1"); cout << "is " << (sw.isConnectedTo(sw2) ? "" : "not ") << "connected" << endl; - // TODO: создать цепь из генератора, выключателя и светильника + Generator generator; + Lamp lamp; + Switch sw3; + + generator.connect("A1", lamp, "A1"); + lamp.connect("A2", sw3, "A1"); + cout << "is " << (generator.isConnectedTo(lamp) ? "" : "not ") << "connected" << endl; + cout << "is " << (lamp.isConnectedTo(sw3) ? "" : "not ") << "connected" << endl; + + generator.disconnect("A1"); + cout << "is " << (generator.isConnectedTo(lamp) ? "" : "not ") << "connected" << endl; return 0; } diff --git a/electricity/electricity.h b/electricity/electricity.h index cb19597..49bf2df 100644 --- a/electricity/electricity.h +++ b/electricity/electricity.h @@ -50,7 +50,11 @@ class Object { /// /// Индекс полюса, от 0 до значения, возвращаемого . /// Полюс с указанным индексом, или nullptr, если такой полюс не существует. - Pole* getPole(size_t idx) { /* TODO */ return nullptr; } + Pole* getPole(size_t idx) { + if (getPole("A" + std::to_string(idx))) + return getPole("A" + std::to_string(idx)); + return nullptr; + } /// /// Возвращает полюс по внутреннему индексу устройства. @@ -135,3 +139,30 @@ class Switch : public Object { // TODO: класс светильника с двумя полюсами // TODO: класс генератора с тремя полюсами (фаза, нейтраль, земпя). +class Lamp : public Object { +public: + Pole a1, a2; + + Lamp(const std::string& name = ""); + + size_t getPoleCount() const override { return 2; } + + const Pole* getPole(const std::string& name) const override; + +protected: + const Pole* getPole(size_t idx) const override; +}; + +class Generator : public Object { +public: + Pole a1, a2, a3; + + Generator(const std::string& name = ""); + + size_t getPoleCount() const override { return 3; } + + const Pole* getPole(const std::string& name) const override; + +protected: + const Pole* getPole(size_t idx) const override; +}; \ No newline at end of file diff --git a/memhacks/memhacks.cpp b/memhacks/memhacks.cpp index 514c868..f6092a2 100644 --- a/memhacks/memhacks.cpp +++ b/memhacks/memhacks.cpp @@ -3,6 +3,8 @@ using namespace std; +A::A() : a_s("It's a!"), foo(0) {} + B::B() : b_s("It's b!") { for (auto i = 0; i < sizeof(data) / sizeof(data[0]); i++) data[i] = i * 2; @@ -13,12 +15,13 @@ B::B() : b_s("It's b!") { /// Можно модифицировать для собственных отладочных целей. /// /// Изучаемый объект -void printInternals(const B& b) { +void printInternals(B& b) { const A* a = &b, * a2 = a + 1; cout << "Address of b is 0x" << &b << ", address of b.a_s is 0x" << &b.a_s << ", address of b.b_s is 0x" << &b.b_s << endl; cout << "Size of A is " << sizeof(A) << ", size of B is " << sizeof(B) << endl; cout << "B string is '" << b.getBString() << "'" << endl; - //cout << "B data: "; b.printData(cout); cout << endl; + cout << "B data printData: "; b.printData(cout); cout << endl; + cout << "B data printData2: "; b.printData2(cout); cout << endl; } /// @@ -27,7 +30,19 @@ void printInternals(const B& b) { /// /// Значение B::b_s std::string A::getBString() const { - // TODO + return *((const string*)(this + 1)); +} + +std::string B::getBString() const { + return b_s; +} + +float A::getData(int idx) const { + return ((float*)(this + 2))[idx]; +} + +float B::getData(int idx) const { + return data[idx]; } /// @@ -37,7 +52,8 @@ std::string A::getBString() const { /// Подразумевается, что текущий объект на самом деле представлено классом . /// void A::printData(std::ostream& os) { - // TODO + os << "A string: " << a_s << ", B string: " << getBString() << ", data: "; + for (int i = 0; i < 7; ++i) os << getData(i) << " "; } /// @@ -46,7 +62,9 @@ void A::printData(std::ostream& os) { /// с помощью виртуальных функций, предусмотренных в классе . /// void A::printData2(std::ostream& os) { - // TODO + B b = *((B*)(this)); + os << "A string: " << a_s << "', B string: " << b.getBString() << ", data: "; + for (int i = 0; i < 7; ++i) os << b.getData(i) << " "; } int main() diff --git a/memhacks/memhacks.h b/memhacks/memhacks.h index 51076b5..4357c89 100644 --- a/memhacks/memhacks.h +++ b/memhacks/memhacks.h @@ -9,10 +9,13 @@ class A { std::string a_s; int foo; - friend void printInternals(const B&); + friend void printInternals(B& b); public: - std::string getBString() const; + A(); + + virtual std::string getBString() const; + virtual float getData(int idx) const; void printData(std::ostream& os); void printData2(std::ostream& os); }; @@ -21,10 +24,13 @@ class B : public A { std::string b_s; float data[7]; - friend void printInternals(const B&); + friend void printInternals(B& b); public: B(); + + virtual std::string getBString() const; + virtual float getData(int idx) const; }; -void printInternals(const B& b); +void printInternals(B& b); diff --git a/memhacks/newhacks.cpp b/memhacks/newhacks.cpp index ba359c6..2f4099d 100644 --- a/memhacks/newhacks.cpp +++ b/memhacks/newhacks.cpp @@ -1,9 +1,51 @@ #include -#include "memhacks.h" +#include "newhacks.h" using namespace std; +Foo::Foo() : cat(), frog() { cerr << "constructed object Foo at " << this << endl; } +Foo::~Foo() { cerr << "destructed object Foo at " << this << endl; } + +void *Foo::operator new(size_t size) { + void *pVoid = malloc(size); + cerr << "operator new(" << size << ") returns " << pVoid << endl; + return pVoid; +} + +void Foo::operator delete(void *pVoid) { + cerr << "operator delete(" << pVoid << ")" << endl; + free(pVoid); +} + +Bar::Bar() : turtle(), dog() { cerr << "constructed object Bar at " << this << endl; } +Bar::~Bar() { cerr << "destructed object Bar at " << this << endl; } + +void *Bar::operator new(size_t size) { + void *pVoid = malloc(size); + cerr << "operator new(" << size << ") returns " << pVoid << endl; + return pVoid; +} + +void Bar::operator delete(void *pVoid) { + cerr << "operator delete(" << pVoid << ")" << endl; + free(pVoid); +} + +Buz::Buz() : snake(), rhinoceros() { cerr << "constructed object Buz at " << this << endl; } +Buz::~Buz() { cerr << "destructed object Buz at " << this << endl; } + int main() { + Foo foo_stack = Foo(); + Bar bar_stack = Bar(); + Buz buz_stack = Buz(); + + Foo* foo_heap = new Foo(); + Bar* bar_heap = new Bar(); + //Buz* buz_heap = new Buz(); => Error + + delete(foo_heap); + delete(bar_heap); + //delete(buz_heap); => Error return 0; -} +} \ No newline at end of file diff --git a/memhacks/newhacks.h b/memhacks/newhacks.h index 079a383..380bbda 100644 --- a/memhacks/newhacks.h +++ b/memhacks/newhacks.h @@ -1,2 +1,38 @@ #pragma once +#include + +class Foo { + int cat; + float frog; +public: + Foo(); + ~Foo(); + + static void *operator new(size_t size); + static void operator delete(void *pVoid); +}; + +class Bar : public Foo { + int turtle; + std::string dog; + +public: + Bar(); + ~Bar(); + + static void *operator new(size_t size); + static void operator delete(void *pVoid); +}; + +class Buz : public Foo { + float snake; + short rhinoceros; + +public: + Buz(); + ~Buz(); + + static void *operator new(size_t size) = delete; + static void operator delete(void *pVoid) = delete; +}; \ No newline at end of file diff --git a/vectors/array.cpp b/vectors/array.cpp index 555ccad..b91cbab 100644 --- a/vectors/array.cpp +++ b/vectors/array.cpp @@ -7,8 +7,11 @@ using namespace std; // 2. operator * (вектор на скаляр и скаляр на вектор; реализация вне класса) // 3. Нахождение среднего для двух векторов (реализация вне класса) -ostream& operator <<(ostream& os, const Vector3d& v) { - return os << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }"; +template +Vector middle(Vector vector_1, Vector vector_2) { + Vector vector; + for (int i = 0; i < Dimensions; ++i) vector[i] = (vector_1[i] + vector_2[i]) / 2; + return vector; } template @@ -20,9 +23,13 @@ ostream& operator <<(ostream& os, const Vector& v) { } int main() { - Vector<12> v1; - v1[1] = v1[2] = 54; - Vector<12> v2 = v1; - cout << v2 << endl; + Vector<7> vector_1 = Vector<7>(7); + Vector<7> vector_2 = Vector<7>(3); + Vector<7> vector_3 = Vector<7>(2); + + cout << "vector_1 + vector_2 = " << vector_1 + vector_2 << endl; + cout << "vector_3 * 5 = " << vector_3 * 5 << endl; + cout << "middle of vector_1, vector_2 = " << middle(vector_1, vector_2) << endl; + return 0; } diff --git a/vectors/array.h b/vectors/array.h index 60f50b2..f3c57f4 100644 --- a/vectors/array.h +++ b/vectors/array.h @@ -2,15 +2,6 @@ #include -class Vector3d { - float data[3]; -public: - Vector3d() { data[2] = data[1] = data[0] = 0; } - Vector3d(float value) { data[2] = data[1] = data[0] = value; } - float operator[] (int index) const { std::cerr << "const" << index << std::endl; return data[index]; } - float& operator[] (int index) { std::cerr << "non-const" << index << std::endl; return data[index]; } -}; - template class Vector { float data[Dimensions]; @@ -18,4 +9,24 @@ class Vector { Vector(float value = 0) { for (size_t i = 0; i < Dimensions; i++) data[i] = value; } float operator[] (size_t index) const { return data[index]; } float& operator[] (size_t index) { return data[index]; } + + Vector operator+ (Vector vector_1) { + Vector vector; + for (size_t i = 0; i < Dimensions; i++) vector[i] = vector_1[i] + data[i]; + return vector; + } }; + +template +Vector operator* (Vector vector_1, float scalar) { + Vector vector; + for (size_t i = 0; i < Dimensions; i++) vector[i] = vector_1[i] * scalar; + return vector; +} + +template +Vector operator* (float scalar, Vector vector_1) { + Vector vector; + for (size_t i = 0; i < Dimensions; i++) vector[i] = vector_1[i] * scalar; + return vector; +} \ No newline at end of file diff --git a/vectors/vector.cpp b/vectors/vector.cpp index 9777069..da415bb 100644 --- a/vectors/vector.cpp +++ b/vectors/vector.cpp @@ -7,19 +7,28 @@ ostream& operator <<(ostream& os, const vector3d& v) { return os << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }"; } -int main(int argc, char** argv) { - vector3d v1, v2(12), v3(1, 3, 8); - v1[2] = 54; - //vector3d v4 = v1 + v2, v5 = v1 - v2, v6 = v1 * 0.5f; - //cout << "v4: " << v4 << endl << "v5: " << v5 << endl << "v6: " << v6 << endl; - - printf("address of v1: 0x%p, size: %zu bytes\n", &v1, sizeof(v1)); - printf("address of v1.data: 0x%p, size: %zu bytes\n", &v1.data, sizeof(v1.data)); - printf("address of v1.data[-1]: 0x%p, size: %zu bytes\n", &v1.data[-1], sizeof(v1.data[-1])); - printf("address of v1.data[0]: 0x%p, size: %zu bytes\n", &v1.data[0], sizeof(v1.data[0])); - printf("address of v1.data[1]: 0x%p, size: %zu bytes\n", &v1.data[1], sizeof(v1.data[1])); - printf("address of v1.data[2]: 0x%p, size: %zu bytes\n", &v1.data[2], sizeof(v1.data[2])); - printf("address of v1.data[2000]: 0x%p, size: %zu bytes\n", &v1.data[2000], sizeof(v1.data[2000])); +bool test_vector3d() { + bool test_plus, test_minus, test_multiply, test_divide, test_unary_minus, test_negate_1, test_negate_2; + vector3d vector_1 = vector3d(1, 2, 3); + vector3d vector_2 = vector3d(4, 5, 6); + vector3d vector_3 = vector3d(0); + test_plus = (vector_1 + vector_2) == vector3d (5, 7, 9); + test_minus = (vector_1 - vector_2) == vector3d (-3); + test_multiply = (vector_1 * 3) == vector3d (3, 6, 9); + test_divide = (vector_2 / 2) == vector3d (2, 2.5, 3); + test_unary_minus = (-vector_1) == vector3d (-1, -2, -3); + test_negate_1 = (!vector_1) == vector3d (0); + test_negate_2 = (!vector_3) == vector3d (1); + if (!test_plus) cerr << "Not correct value operator+, vector_1: " << vector_1 << ", vector_2: " << vector_2 << endl; + if (!test_minus) cerr << "Not correct value operator-, vector_1: " << vector_1 << ", vector_2: " << vector_2 << endl; + if (!test_multiply) cerr << "Not correct value operator*, vector_1: " << vector_1 << ", scalar: 3 " << endl; + if (!test_divide) cerr << "Not correct value operator/, vector_1: " << vector_1 << " scalar: 2 " << endl; + if (!test_unary_minus) cerr << "Not correct value operator-, vector_1: " << vector_1 << endl; + if (!test_negate_1) cerr << "Not correct value operator!, vector_1: " << vector_1 << endl; + if (!test_negate_2) cerr << "Not correct value operator!, vector_3: " << vector_3 << endl; + return false; +} - return 0; +int main(int argc, char** argv) { + return !test_vector3d(); } diff --git a/vectors/vector.h b/vectors/vector.h index 07587fb..1aa4e3b 100644 --- a/vectors/vector.h +++ b/vectors/vector.h @@ -13,7 +13,27 @@ class vector3d { float& operator[](int idx) { return data[idx]; } float operator[](int idx) const { return data[idx]; } - friend int main(int argc, char** argv); + vector3d operator+ (vector3d vector) { + return vector3d(data[0] + vector[0], data[1] + vector[1], data[2] + vector[2]); + } + vector3d operator- (vector3d vector) { + return vector3d(data[0] - vector[0], data[1] - vector[1], data[2] - vector[2]); + } + vector3d operator* (float scalar) { + return vector3d(data[0] * scalar, data[1] * scalar, data[2] * scalar); + } + vector3d operator/ (float scalar) { + return vector3d(data[0] / scalar, data[1] / scalar, data[2] / scalar); + } + vector3d operator- () { + return vector3d(-data[0], -data[1], -data[2]); + } + vector3d operator! () { + return vector3d(!data[0] && !data[1] && !data[2]); + } + bool operator== (vector3d vector) { + return data[0] == vector[0] && data[1] == vector[1] && data[2] == vector[2]; + } }; std::ostream& operator <<(std::ostream& os, const vector3d& v);