-
Notifications
You must be signed in to change notification settings - Fork 0
/
07.template.cpp
63 lines (53 loc) · 1.02 KB
/
07.template.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
55
56
57
58
59
60
61
62
63
// simple arithmetic on generic class
#include<iostream>
using namespace std;
template <class T>
class arithmetic{
private:
T a;
T b;
public:
arithmetic();
arithmetic(T a, T b);
T add();
T sub();
T multiply();
float division();
};
template <class T>
arithmetic<T>::arithmetic(){
this->a = 1;
this->b = 1;
}
template <class T>
arithmetic<T>::arithmetic(T a, T b){
this->a = a;
this->b = b;
}
template <class T>
T arithmetic<T>::add(){
return a+b;
}
template <class T>
T arithmetic<T>::sub(){
return a-b;
}
template <class T>
T arithmetic<T>::multiply(){
return a*b;
}
template <class T>
float arithmetic<T>::division(){
return (float)a/b;
}
int main(){
float x,y;
cout<<"enter two numbers: "<<endl;
cin>>x>>y;
arithmetic<float> a(x,y);
cout<<"Addition is: "<<a.add()<<endl;
cout<<"Sub is: "<<a.sub()<<endl;
cout<<"Mult is: "<<a.multiply()<<endl;
cout<<"Division is: "<<a.division();
return 0;
}