C++ program to swap two numbers using class

C++ program to swap two numbers using class

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

class swap
{
int a,b;
public:
void getdata();
void swapv();
void display();
};

void swap::getdata()
{
cout<<“Enter two numbers:”;
cin>>a>>b;
}

void swap::swapv()
{
a=a+b;
b=a-b;
a=a-b;
}

void swap::display()
{
cout<<“a=”<<a<<“tb=”<<b;
}

main()
{
clrscr();
swap s;

s.getdata();
cout<<“nBefore swap:n”;
s.display();

s.swapv();
cout<<“nnAfter swap:n”;
s.display();

getch();
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *