Create a function Maximum using templates, your function should have the following prototype
t Maximum (t x, t y)
This function should return the maximum values out of the two values being passed, in your main function create variables of different types, integer, character and double and check what your function returns for each different variable type.
#include <iostream>
#include <string>
using namespace std;
template<typename t>
t Maximum (t x, t y){
if(x>y){
return x;
}
return y;
}
int main(){
cout<<"Maximum(4,6): "<<Maximum(4,6)<<"\n";
cout<<"Maximum(n,a): "<<Maximum('n','a')<<"\n";
cout<<"Maximum(45.65,25.6): "<<Maximum(45.65,25.6)<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment