#include <iostream>
using namespace std;
template <class T>
class Vector
{
friend istream & operator >> (istream & is, Vector & v)
{
cout<<"Vvedit vector rozmirom "<<v.n<<":"<<endl;
for(int i = 0; i <v.n; i++)
is>>v.a[i];
return is;
}
friend ostream & operator << (ostream & os, const Vector & v)
{
v.show();
return os;
}
private:
T *a; // masiv
int n; // rozmir mas
public:
Vector();
Vector(int _n);
Vector(const Vector & v);//конструктор копіювання
void show()const;
//void setN();
~Vector();
Vector operator + (const Vector & g);
Vector operator = (const Vector & g);
T operator * (const Vector & g);
};
//
//template <class T>
// void Vector<T>::setN(int _n)
// {
// n = _n;
// };
template <class T>
Vector<T> ::Vector()
{
n=3;
a = new T [3];
for(int i = 0; i < n; i++)
a[i] = 0;
}
template <class T>
Vector<T>::Vector(int _n)
{
n=_n;
a = new T [_n];
for(int i = 0; i < _n; i++)
a[i] = 0;
}
template <class T>
void Vector<T>::show()const
{
for(int i = 0; i < n; i++)
cout<<a[i]<<" ";
cout<<endl;
};
template <class T>
Vector<T>::~Vector()
{
//cout<<"distruct"<<endl;
delete []a;
};
template <class T>
Vector<T> Vector<T>::operator + (const Vector<T> & g)
{
Vector res(n);
if(n != g.n)
{
cout<<"no rozmir"<<endl;
return res;
} else {
for(int i = 0; i < n; i++)
{
res.a[i] = a[i] + g.a[i];
}
cout<<"resultat: "<<res<<endl;
return res;
}
}
template <class T>
T Vector<T>::operator * (const Vector<T> & g){
T suma = 0;
if(n != g.n){
cout<<"no rozmir"<<endl;
return suma;
} else {
for(int i = 0; i<n; i++)
{
suma += a[i] * g.a[i];
}
}
return suma;
}
template <class T>
Vector<T> Vector<T>::operator = (const Vector<T> & g)
{
//cout<<"operator = "<<endl;
Vector res(g.n);
for (int i = 0; i < g.n; i++)
{
res.a[i] = g.a[i];
}
return res;
}
template <class T>
Vector<T>::Vector(const Vector<T> & v)
{
if(this != &v)//порівнюєм дві адреси
{
//cout<<"construkt copy: "<<endl;
n = v.n;
a = new T[n];
for (int i = 0; i < v.n; i++)
{
a[i] = v.a[i];
}
}
}
int main()
{
Vector<int>* array = new Vector<int>[3];
for (int i = 0; i < 3; i++)
{
cin >> array[i];
}
Vector <int> sum;
sum = array[0] + array[1] + array[2] ;
cout << "The sum of all 3 vectors is: " << sum << endl;
system("PAUSE");
return 0;
}