-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTemplate_5.cpp
54 lines (47 loc) · 1.16 KB
/
Template_5.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
const int MAX = 3;
template <class T>
class vector
{
public:
T* v; //type T vector
vector()
{
v = new T[MAX];
for (int i=0; i<MAX; i++)
v[i] = 0;
}
void operator=(T *y)
{
for (int i=0; i<MAX; i++)
this->v[i] = y[i];
}
T operator*(vector &y)
{
T sum = 0;
for (int i=0; i<MAX; i++)
{
sum = sum + this->v[i] * y.v[i];
}
return sum;
}
};
int main()
{
int x[MAX] = {1, 2, 3};
int y[MAX] = {4, 5, 6};
vector <int> v1;
vector <int> v2;
v1 = x;
v2 = y;
cout<<"\nVector v1: ";
for(int i = 0; i<MAX ;i++)
cout<<" "<<v1.v[i];
cout<<"\nVector v2: ";
for(int i = 0; i<MAX ;i++)
cout<<" "<<v2.v[i];
int R = v1 * v2;
cout << "\nR = " << R << "\n";
return 0;
}