// template class for 3D vectors, plus test main
#include <iostream.h>

template <class T>
class Vector {
	public:
		// ---- constructors ----

		Vector(T init_x = 0, T init_y = 0, T init_z = 0) 
		// postcondition:  x = init_x, y = init_y, z = init_z
		{
			x = init_x; y = init_y; z = init_z;
		}

		// ---- "constant" member functions ----
		
		T get_x(void) const
		// postcondition:  return value is x coordinate
		{
			return x;
		}
			
		T get_y(void) const
		// postcondition:  return value is y coordinate
		{
			return y;
		}

		T get_z(void) const
		// postcondition:  return value is z coordinate
		{
			return z;
		}

		void show(char identifier[]) const
		// postcondition:  x, y, z coordinates printed to cout,
		//	preceded by identifier and followed by endl
		{
			cout << identifier << " = (";
			cout << x << ", " << y << ", " << z;
			cout << ")\n";
		}


	private:
		T x, y, z;
};

// ---- nonmember functions ----

template <class T>
Vector<T> add(const Vector<T> & v1, const Vector<T> & v2)
// postcondition:  return value is sum of v1 and v2
{
	return Vector<T>(v1.get_x() + v2.get_x(),
		v1.get_y() + v2.get_y(),
		v1.get_z() + v2.get_z());
}

template <class T>
Vector<T> subtract(const Vector<T> & v1, const Vector<T> & v2)
// postcondition:  return value is difference of v1 and v2
{
	return Vector<T>(v1.get_x() - v2.get_x(),
		v1.get_y() - v2.get_y(),
		v1.get_z() - v2.get_z());
}

// ---- main program to test a few things ----

int main()
{
	Vector<int> v1 = Vector<int>(1, 2, 3);
	Vector<int> v2 = Vector<int>(2, 4, 6);
	Vector<int> vtemp;

	v1.show("v1");
	v2.show("v2");

	vtemp = add(v1, v2);
	vtemp.show("v1 + v2");

	vtemp = subtract(v1, v2);
	vtemp.show("v1 - v2");

	Vector<double> z1 = Vector<double>(1.1, 2.2, 3.3);
	Vector<double> z2 = Vector<double>(2.2, 4.4, 6.6);
	Vector<double> ztemp;

	z1.show("z1");
	z2.show("z2");

	ztemp = add(z1, z2);
	ztemp.show("z1 + z2");

	ztemp = subtract(z1, z2);
	ztemp.show("z1 - z2");

	return 0;

}