#include<math.h>
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
// **********
 
// Klassentemplate Vector_2d.
 
template<typename T> class Vector_2d
{
public:
 
  Vector_2d(T x_, T y_)
  {
    x = x_;
    y = y_;
  }
 
  T norm()
  {
    return sqrt(x*x + y*y);	
  }
 
  void Print();
 
  T x;
  T y;
};
 
template<typename T> void Vector_2d<T>::Print()
{
  printf("(%+.3f , %+.3f)", (double)x, (double)y);
}
 
// **********
 
// Funktionentemplate zur streambasierten Ausgabe von Objekten vom Typ Vector_2d<T>.
// Der Ausgabeoperator << wird überladen.
 
template<typename T> ostream &operator<<(ostream &s, const Vector_2d<T> &v)
{
  return s << "(" << v.x << " , " << v.y << ")";
}
 
// **********
 
int main(void)
{
  Vector_2d<int> v1(1, 2);
  printf("v1 = ");  // Ausgabe im C-Stil.
  v1.Print();
  printf("\n");
  cout << "v1 = " << v1 << endl;  // Stream-basierte Ausgabe im C++-Stil.
 
  Vector_2d<double> v2(3.3, 4.4);
  printf("v2 = ");  // Ausgabe im C-Stil.
  v2.Print();
  printf("\n");
  cout << "v2 = " << v2 << endl;  // Stream-basierte Ausgabe im C++-Stil.
}

