Sem 3‎ > ‎OOPS (C++) LAB‎ > ‎

Q2. WAP to swap two numbers using classes.

posted Jul 28, 2011, 9:14 AM by Neil Mathew   [ updated Jul 28, 2011, 9:33 AM ]

SOURCE CODE:


#include<iostream.h>
#include<conio.h>



class Swap
{
int a;
int b;

public:

void Get()
{
cout<<"\n Enter Number A: ";
cin>>a;
cout<<"\n Enter Number B: ";
cin>>b;
}


void Swapper()
{
cout<<"\n\n Swapping... ";
int temp;
temp=a;
a=b;
b=temp;
}

void Show()
{
cout<<"\n Number A: "<<a;
cout<<"\n Number B: "<<b;
}

};

void main()
{
clrscr();

Swap s1;

s1.Get();
s1.Swapper();
s1.Show();

getch();

}


OUTPUT:



Comments