Vous êtes sur la page 1sur 1

Program 7:

Template design in C++


#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<<"m and n before
swap:"<<m<<"\t"<<n<<"\n";
swap(m,n);
cout<<"m and n after
swap:"<<m<<"\t"<<n<<"\n";
cout<<"a and b before
swap:"<<a<<"\t"<<b<<"\n";
swap(a,b);
cout<<"a and b after
swap:"<<a<<"\t"<<b<<"\n";
}
int main ()
{
int m,n;
float a,b;
clrscr();
cout<<"enter integer value for m and n ";
cin >> m>>n;
cout<<"enter float value for a and b ";
cin >> a>>b;
fun(m,n,a,b);
getch();
return 0;
}

Vous aimerez peut-être aussi