-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.cpp
51 lines (47 loc) · 848 Bytes
/
templates.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
#include<iostream>
using namespace std;
//1st EXAMPLE
// template<class T>
// class Vector{
// T a;
// public:
// Vector(T a){
// this->a=a;
// }
// void display(){
// cout<<"The value of a is "<<a<<endl;
// }
// };
//2nd EXAMPLE
template<class T>
class dot{
public:
T *arr;
int size;
dot(int a){
size=a;
arr=new T[size];
}
T dotproduct(dot &d){
T dp=0;
for(int i=0;i<size;i++){
dp+=this->arr[i]*d.arr[i];
}
return(dp);
}
};
int main(){
// Vector<char>vec('H');
// vec.display();
dot<float>obj(3);
obj.arr[1]=1.1;
obj.arr[2]=0.1;
obj.arr[3]=2.2;
dot<float>obj1(3);
obj1.arr[1]=0;
obj1.arr[2]=1.1;
obj1.arr[3]=0;
float b=obj.dotproduct(obj1);
cout<<b<<endl;
return 0;
}