-
Notifications
You must be signed in to change notification settings - Fork 0
/
templateFunClass.cpp
69 lines (57 loc) · 1.41 KB
/
templateFunClass.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
64
65
66
67
68
69
/**
* @file templateFunClass.cpp
* create a template function inside class and find the largest and smallest number among 3 numbers.
* @author Md. Alamin (alamin5g@yahoo.com)
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-04-23
*
* @copyright Copyright (c) 2022
*
*/
#include <bits/stdc++.h>
using namespace std;
class LargestNumber{
private:
double a, b, c;
public:
///for finding largest number
template<typename T>
T largestNum(T a, T b, T c){
this->a = a;
this->b = b;
this->c = c;
if(a>b && a>c){
return a;
}else if(b>a && b>c){
return b;
}else{
return c;
}
}
///for finding smallest number
template<typename T>
T smallestNum(T a, T b, T c){
this->a = a;
this->b = b;
this->c = c;
if(a<b && a<c){
return a;
}else if(b<a && b<c){
return b;
}else{
return c;
}
}
};
int main(){
double x, y, z, l,s;
cin >> x >> y>> z;
LargestNumber largest;
l = largest.largestNum(x, y, z);
cout << "Largest Number is: " << l << endl;
LargestNumber smallest;
s = smallest.smallestNum(x,y,z);
cout << "Smallest Number is: " << s << endl;
return 0;
}