as

Write a C++ program to demonstrate function template.

Write a C++ program to demonstrate function template.  




Code :-
/********************************************************* TITLE:Programe for function temp. **********************************************************/ #include<iostream.h> #include<conio.h> template <class t> void swap( t &x, t&y) { t temp; temp = x; x = y; y = temp; } void  fun(int m, int n,float a, float b) { cout << "\n For Integer Value"; cout << "\n m and n before swap \n"; cout << m << "\t" << n; swap(m,n); cout << "\n m and n after swap \n"; cout << m << "\t" << n; cout<<"\n\n For Float Value"; cout << "\n m and n before swap \n"; cout << a << "\t" << b; swap(a,b); cout << "\n m and n after swap \n"; cout << a << "\t" << b; } void main() { clrscr(); fun(100,200,11.11,22.22); getch(); } /*********************************************** OUT PUT  For Integer Value  m and n before swap 100     200  m and n after swap 200     100  For Float Value  a and b before swap 11.11   22.219999  a and b after swap 22.219999       11.11 ************************************************/
Output :-

 For Integer Value
 m and n before swap
100     200
 m and n after swap
200     100

 For Float Value
 a and b before swap
11.11   22.219999
 a and b after swap
22.219999       11.11