1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <fstream>
using namespace std;
class Vector3D {
private:
double x, y, z;
public:
Vector3D (double x=0, double y=0, double z=0) : x(x), y(y), z(z) {
}
friend ostream& operator << (ostream& s, Vector3D v){
return s << v.x << "," << v.y << "," << v.z;
}
friend Vector3D operator *(Vector3D a, Vector3D b){
return double(a.x*b.x+a.y*b.y+a.z*b.z);
}
};
int main() {
Vector3D a(2.5, 2.0, 1.0);
Vector3D b(-1, 1, 0);
double c = a * b;
cout << c << '\n';
}
|