-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTemplateCalculator.cpp
More file actions
57 lines (55 loc) · 934 Bytes
/
TemplateCalculator.cpp
File metadata and controls
57 lines (55 loc) · 934 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
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
template<class T>
class cal
{
public:
T a,b,c;
void getdata();
T add(T x,T y);
T sub(T x,T y);
T mul(T x,T y);
T div(T x,T y);
T mod(T x,T y);
};
template<class T>
void cal<T>::getdata()
{
cout<<"Enter First and second number";
cin>>a>>b;
}
template<class T>
T cal<T>::add(T x, T y)
{
return x+y;
}
template<class T>
T cal<T>::sub(T x,T y)
{
return x-y;
}
template<class T>
T cal<T>::mul(T x,T y)
{
return x*y;
}
template<class T>
T cal<T>::div(T x,T y)
{
return x/y;
}
template<class T>
T cal<T>::mod(T x,T y)
{
return int(x)%int(y);
}
int main()
{
cal<float> ob1;
ob1.getdata();
cout<<"\nSum is "<<ob1.add(ob1.a,ob1.b);
cout<<"\nDifference is "<<ob1.sub(ob1.a,ob1.b);
cout<<"\nProduct is "<<ob1.mul(ob1.a,ob1.b);
cout<<"\nQuotient is "<<ob1.div(ob1.a,ob1.b);
cout<<"\nModulus is "<<ob1.mod(ob1.a,ob1.b);
}