-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10b.cpp
More file actions
45 lines (38 loc) · 996 Bytes
/
Copy path10b.cpp
File metadata and controls
45 lines (38 loc) · 996 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
#include <iostream>
using namespace std;
// Template class for a simple pair
template <typename T>
class MyPair {
private:
T a, b;
public:
// Constructor
MyPair(T first, T second) {
a = first;
b = second;
}
// Function to get maximum
T getMax() {
return (a > b) ? a : b;
}
// Function to display values
void display() {
cout << "Values: " << a << ", " << b << endl;
}
};
int main() {
// Pair of integers
MyPair<int> intPair(10, 20);
intPair.display();
cout << "Max: " << intPair.getMax() << endl << endl;
// Pair of doubles
MyPair<double> doublePair(5.6, 3.4);
doublePair.display();
cout << "Max: " << doublePair.getMax() << endl << endl;
// Pair of characters
MyPair<char> charPair('a', 'z');
charPair.display();
cout << "Max: " << charPair.getMax() << endl;
return 0;
}
Output