All pastes #604865 Raw Edit

Something

public text v1 · immutable
·published 2007-07-05 20:32 UTC
rendered paste body
#include <iostream>
#include <windows.h>
#include <GL/gl.h>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

struct My3DVector {
	double _x;
	double _y;
	double _z;
	My3DVector(double x=0, double y=0, double z=0)
	{
		_x = x;
		_y = y;
		_z = z;
	}
	double GetLength() const {
		return ::sqrt(_x*_x + _y*_y + _z*_z);
	}
	My3DVector operator +(const My3DVector& op2) {
		double newx = _x + op2._x;
		double newy = _y + op2._y;
		double newz = _z + op2._z;
		return My3DVector(newx, newy, newz);
	}
	My3DVector operator -(const My3DVector& op2) {
		double newx = _x - op2._x;
		double newy = _y - op2._y;
		double newz = _z - op2._z;

		return My3DVector(newx, newy, newz);
	}
	My3DVector& operator *(double alpha) {//scale
		double newx = _x * alpha;
		double newy = _y * alpha;
		double newz = _z * alpha;
		//return My3DVector(newx, newy, newz);
		return *this;
	}
	double operator * (const My3DVector& v) {//dot product
		double res = v._x * _x  + v._y  * _y + v._z * _z;
		return res;
	}
	My3DVector operator ^ (const My3DVector& op2) const {
		//double res = M
	}


};
using std::ostream;
ostream& operator << (ostream& os, const My3DVector& v) {
	os<<"x: "<<v._x<<endl;
	os<<"y: "<<v._y<<endl;
	os<<"z: "<<v._z<<endl;
	return os;
}
int main() {
	My3DVector u(1.5, 2.3, 9.0), v(-1,3,4), a;

	a = u + v;
	cout <<u<<endl;;
	cout<<a<<endl;;
	cout<<u-v;
	cout <<"Bonjour World"<<endl;
	cin.ignore();
	return - 1;
}