-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtemplates.cpp
More file actions
48 lines (45 loc) · 717 Bytes
/
templates.cpp
File metadata and controls
48 lines (45 loc) · 717 Bytes
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
#include <iostream>
#include <string>
using namespace std;
template<class T>
class vector
{
T *v;
int size;
public:
vector(int m)
{
v = new T[m];
size = m;
for(int i=0;i<m;i++)
v[i] = 0;
}
void read()
{
for(int i=0;i<size;i++)
cin >> this->v[i];
}
T operator *(vector &y)
{
T sum=0;
for(int i=0;i<size;i++)
sum+=this->v[i]*y.v[i];
return sum;
}
~vector(){}
};
int main()
{
int size;
cout << "Enter size of vector: ";
cin >> size;
vector <float> v1(size);
vector <float> v2(size);
cout << "Enter values for vector 1: " << endl;
v1.read();
cout << "Enter values for vector 2: " << endl;
v2.read();
float R = v1*v2;
cout << "Sum of 2 vectors: " << R << endl;
return 0;
}