#include <iostream>
#include <vector>
using namespace std;
class Vector3d
{
public:
struct Punto
{
int x;
int y;
int z;
};
public:
Vector3d();
Vector3d(int x, int y, int z );
Vector3d operator+(const Vector3d& v);
Vector3d operator*(const Vector3d& v);
Vector3d operator+=(const Vector3d& v);
void escalar(int s);
void setVector3d(int x, int y, int z);
void imprimir();
private:
Punto p;
vector<Punto> puntos;
};
Vector3d::Vector3d()
{
}
Vector3d::Vector3d(int x, int y, int z)
{
p.x = x;
p.y = y;
p.z = z;
puntos.push_back(p);
}
Vector3d Vector3d::operator+(const Vector3d& v)
{
Vector3d result;
Punto temp;
for (int i = 0; i < v.puntos.size(); i++)
{
temp.x = this->puntos[i].x + v.puntos[i].x;
temp.y = this->puntos[i].y + v.puntos[i].y;
temp.z = this->puntos[i].z + v.puntos[i].z;
result.puntos.push_back(temp);
}
return result;
}
Vector3d Vector3d::operator*(const Vector3d& v)
{
Vector3d result;
Punto temp;
for (int i = 0; i < v.puntos.size(); i++)
{
temp.x = this->puntos[i].x * v.puntos[i].x;
temp.y = this->puntos[i].y * v.puntos[i].y;
temp.z = this->puntos[i].z * v.puntos[i].z;
result.puntos.push_back(temp);
}
return result;
}
Vector3d Vector3d::operator+=(const Vector3d& v)
{
Punto temp;
for (int i = 0; i < v.puntos.size(); i++)
{
this->puntos[i].x = this->puntos[i].x + v.puntos[i].x;
this->puntos[i].y = this->puntos[i].y + v.puntos[i].y;
this->puntos[i].z = this->puntos[i].z + v.puntos[i].z;
}
return *this;
}
void Vector3d::escalar(int s)
{
for (int i = 0; i < this->puntos.size(); i++)
{
this->puntos[i].x = this->puntos[i].x * s;
this->puntos[i].y = this->puntos[i].y * s;
this->puntos[i].z = this->puntos[i].z * s;
}
}
void Vector3d::setVector3d(int x, int y, int z)
{
Punto temp;
temp.x = x;
temp.y = y;
temp.z = z;
this->puntos.push_back(temp);
}
void Vector3d::imprimir()
{
for (int i = 0; i < puntos.size(); i++)
{
if (i != 0) cout << ", ";
cout << "(" << puntos[i].x
<< ", " << puntos[i].y
<< ", " << puntos[i].z << ")";
}
}
int main()
{
Vector3d v1;
cout << "\nv1: "; v1.imprimir();
Vector3d v2(1, 2, 3);
cout << "\nv2: "; v2.imprimir();
v2.setVector3d(4, 5, 6);
cout << "\nv2: "; v2.imprimir();
Vector3d v3(2, 2, 2);
v3.setVector3d(3, 3, 3);
cout << "\nv3: "; v3.imprimir();
Vector3d v4 = v2 + v3;
cout << "\nv4 = v2 + v3: "; v4.imprimir();
v4 += v3;
cout << "\nv4 += v3: "; v4.imprimir();
Vector3d v5 = v3 * v4;
cout << "\nv5 = v3 * v4: "; v5.imprimir();
v5.escalar(2);
cout << "\nv5 = v5 * 2: "; v5.imprimir();
cout << endl;
return 0;
}