#include<iostream> #include<string.h> using namespace std; class swapp{ public: int itemp; float ftemp; char ctemp[100]; void swap_it(int num1,int num2) { cout<<"\nBEFORE SWAPPING :"<<"\n"<<"NUM1: "<<num1<<"\nNUM2 :"<<num2; itemp=num1; num1=num2; num2=itemp; cout<<"\nAFTER SWAPPING :"<<"\nNUM1: "<<num1<<"\nNUM2 :"<<num2; } void swap_it(float num1,float num2) { cout<<"\nBEFORE SWAPPING :"<<"\n"<<"NUM1: "<<num1<<"\nNUM2 :"<<num2; ftemp=num1; num1=num2; num2=ftemp; cout<<"\nAFTER SWAPPING :"<<"\n"<<"NUM1: "<<num1<<"\nNUM2 :"<<num2; } void swap_it(char c1[100],char c2[100]) { cout<<"\nBEFORE SWAPPING :"<<"\n"<<"CHAR1 :"<<c1<<"\nCHAR2 :"<<c2; strcpy(ctemp,c1); strcpy(c1,c2); strcpy(c2,ctemp); cout<<"\nAFTER SWAPPING :"<<"\n"<<"CHAR1 :"<<c1<<"\nCHAR2 :"<<c2; } }; int main() { swapp swapp; int i1,i2; float f1,f2; char c1[100],c2[100]; cout<<"\nENTER THE INTEGER VARIABLES"; cin>>i1>>i2; swapp.swap_it(i1,i2); cout<<"\nENTER THE FLOAT VARIABLES"; cin>>f1>>f2; swapp.swap_it(f1,f2); cout<<"\nENTER THE CHARACTER VARIABLES"; cin>>c1>>c2; swapp.swap_it(c1,c2); return 0; }
New Android apps UniqueKey
Saturday, 21 March 2015
Swapping using Function Overloading
Labels:
C plus,
C++ Language
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment