What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

C++ Lab Codings

C++ Program for TO SWAP USING TEMPLATE FUNCTION.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
template<class S>
void swap(S &a,S &b)
{
S t;
t=a;
a=b;
b=t;
}
void main()
{
int a,b;
float c,d;
char e,f;
char *str1="AKILA",*str2="KRISHNA";
clrscr();
cout<<"\n\n\t\tPROGRAM TO SWAP USING TEMPLATE FUNCTION\n\n";
cout<<"\n\n\tEnter the value for a & b <int>: ";
cin>>a>>b;
cout<<"\n\n\tEnter the Value for c & d <float>: ";
cin>>c>>d;
cout<<"\n\n\tEnter the Value for e & f <char> : ";
fflush(stdin);
cin>>e>>f;
clrscr();
cout<<"\n\n\t\tSWAPPING USING TEMPLATE FUNCTION\n";
cout<<"\n\n\t\tINTEGER SWAPPING";
cout<<"\n\n\t\tBefore Swap : a = "<<a<<"\tb = "<<b;
swap(a,b);
cout<<"\n\n\t\tAfter Swap : a = "<<a<<"\tb = "<<b;
cout<<"\n\n\t\tFLOAT SWAPPING";
cout<<"\n\n\t\tBefore Swap : c = "<<c<<"\td = "<<d;
swap(c,d);
cout<<"\n\t\tAfter Swap : c = "<<c<<"\td = "<<d;
cout<<"\n\n\t\tCHARACTER SWAPPING";
cout<<"\n\n\t\tBefore Swap : e = "<<e<<"\tf = "<<f;
swap(e,f);
cout<<"\n\t\tAfter Swap : e = "<<e<<"\tf = "<<f;
cout<<"\n\n\t\tSTRING SWAPPING";
cout<<"\n\n\t\tBefore Swap : str1 = "<<str1<<"\tstr2 = "<<str2;
swap(str1,str2);
cout<<"\n\t\tAfter Swap : str1 = "<<str1<<"\tstr2 = "<<str2;
getch();
}

More Lab Programs with Answers -Given Below-Click and Get Freely

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com