-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path57templatecode.cpp
More file actions
43 lines (41 loc) · 797 Bytes
/
Copy path57templatecode.cpp
File metadata and controls
43 lines (41 loc) · 797 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
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
template <class T>
class Vector
{
int size;
public:
T *arr;
Vector(int m) : size(m)
{
arr = new T[size];
}
T DotProduct(Vector v)
{
T d = 0;
for (int i = 0; i < size; i++)
{
d += this->arr[i] * v.arr[i];
}
return d;
}
};
int main()
{
Vector<float> v1(3), v2(3);
cout << "Enter first vector dimensions i, j, k : " << endl;
for (int i = 0; i < 3; i++)
{
cin >> v1.arr[i];
}
cout << "Enter second vector dimensions i, j, k : " << endl;
for (int i = 0; i < 3; i++)
{
cin >> v2.arr[i];
}
float dp = v1.DotProduct(v2);
cout << "V1 . V2 = " << dp << endl;
return 0;
}