This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//template overloading | |
#include<iostream> | |
#include<conio.h> | |
using namespace std; | |
template<class X> //template creation | |
X mins(X x,X y) //template function | |
{ | |
return (x>y)?x:y; | |
} | |
int mins(int x,int y,int z) //template function | |
{ | |
return ( x>y?(x>z?x:z):(y>z?y:z) ); | |
} | |
int main() | |
{ | |
int n1,n2; | |
cout<<"Enter a number "; | |
cin>>n1; | |
cout<<"Enter a number "; | |
cin>>n2; | |
cout<<"Comparing numbers "<<mins(n1,n2); | |
float p1,p2; | |
cout<<"\nEnter a number "; | |
cin>>p1; | |
cout<<"Enter a number "; | |
cin>>p2; | |
cout<<"Comparing numbers "<<mins(p1,p2); | |
int q1,q2,q3; | |
cout<<"\nEnter a number "; | |
cin>>q1; | |
cout<<"Enter a number "; | |
cin>>q2; | |
cout<<"Enter a number "; | |
cin>>q3; | |
cout<<"Comparing numbers "<<mins(q1,q2,q3); | |
getch(); | |
return 0; | |
} | |
Comments
Post a Comment
Thanks for the comment and don't forget to subscribe.