Saturday, May 14, 2016

Write a program cointaning abs(data type) function supporting any vaild inbuilt data type. (template functions).


#include<iostream.h>
#include<conio.h>
template <class T>
T Large(T n1, T n2)
{
return (n1>n2) ? n1:n2;
}
void main()
{
int i1, i2;
float f1, f2;
char c1, c2;
cout<<"Enter integers: ";
cin>>i1;
cout<<"Enter integers: ";
cin>>i2;
cout<<Large(i1, i2)<<" is larger.";
cout<<"\n\nEnter floating-point numbers: ";
cin>>f1;
cout<<"\n\nEnter floating-point numbers: ";
cin>>f2;
cout<<Large(f1, f2)<<" is larger.";
cout<<"\n\nEnter characters: ";
cin>>c1;
cout<<"\n\nEnter characters: ";
cin>>c2;
cout<<Large(c1, c2)<<" has larger ASCII value.";
getch();
}

No comments:

Post a Comment