Search This Blog

Monday 18 April 2016

WAP to swap the numbers using the concept of function template

Practical 30

#include <iostream>
using namespace std;

template <class Gajjar> 
 
void swapab(Gajjar &a, Gajjar &b)
{
  Gajjar temp;
  temp = a;
  a = b;
  b = temp;
}

int main()
{
  int i,j; 
  cout<<"\nEnter int i and j:";
  cin>>i>>j;
  cout<<"\nBefore Swapping With Template: int i & j:"<<i<<" "<<j;
  swapab(i,j);
  cout<<"\nAfter swapping with template int i & j:"<<i<<" "<<j;

  float a,b;
  cout<<"\nEnter float a and b:";
  cin>>a>>b;
  cout<<"\nBefore Swapping With Template: float a & b:"<<a<<" "<<b;
  swapab(a,b); 
  cout<<"\nAfter swapping with template float a & b:"<<a<<" "<<b;    
 return 0;
}

No comments:

Post a Comment