/* Project done in the classroom 17/04/2024 https://tarini.di.unimi.it/teaching/3DVG2026/c++lab/ */ #include class Vector { public: float x, y, z; void print() const { std::cout << "(" << x << ", " << y << ", " << z << ")" << std::endl; } // constructor Vector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} // empty constructor Vector() : x(0), y(0), z(0) {} // Vector sum Vector sum(const Vector& b) const { Vector result; result.x = x + b.x; result.y = y + b.y; result.z = z + b.z; return result; } // Same as above, but defined as the overloading of operator "+" // Vector sum out of place Vector operator +(const Vector& b) const { return Vector(x + b.x, y + b.y,z + b.z); } // overloading of the binary "-" operator: // Vector difference Vector operator -(const Vector& b) const { return Vector(x - b.x, y - b.y,z - b.z); } // overloading of the uniary "-" operator: // Vector flip Vector operator -() const { return Vector(-x, -y, -z); } }; int main() { Vector a(5, 3, -6); Vector b(1, 1, 1); Vector c(6, -3, 5.0); // Vector t = v.sum(w); Vector d = a + b - c; d = -a; d.print(); return 0; }