/* Filename: templat6.cpp Author: Br. David Carlson Date: August 2, 2003 This program uses a template function to display the maximum of various pairs of values. Since the template function uses a type, the function can be used on pairs of intergers, pairs of characters, etc. The only requirement is that the two items be comparable using the > operator. Tested with: Microsoft Visual C++ 2019 */ #include using namespace std; /* Given: First A data item of type T. Second Another data item of type T. Task: To find the maximum of First and Second. Assumes: That > works for data of type T. Return: The maximum item is returned in the function name. */ template T Maximum(T First, T Second) { if (First > Second) return First; else return Second; } int main(void) { cout << "Maximum of 5 and -2 is: " << Maximum(5, -2) << endl; cout << "Maximum of -44 and 33 is: " << Maximum(-44, 33) << endl; cout << "Maximum of 2.56 and 7.92 is: " << Maximum(2.56, 7.92) << endl; cout << "Maximum of 8L and 12L is: " << Maximum(8L, 12L) << endl; cout << "Maximum of 6.66 and 1.25 is: " << Maximum(6.66, 1.25) << endl; cout << "Maximum of 77 and 77 is: " << Maximum(77, 77) << endl; cout << "Maximum of 'A' and 'B' is: " << Maximum('A', 'B') << endl; cout << "Maximum of 'A' and 'a' is: " << Maximum('A', 'a') << endl; return 0; }