#include<iostream.h>
#include<conio.h>
class swap
{
private:
int a,b;
public:
void read()
{
cout<<"\nenter the value of a and b ";
cin>>a>>b;
}
void display(void)
{
cout<<"\nvalue of a = "<<a;
cout<<"\nvalue of b = "<<b;
}
void swp_val(void);
};
void swap::swp_val()
{
a=a+b;
b=a-b;
a=a-b;
}
void main()
{
class swap s;
clrscr();
s.read();
s.display();
cout<<"\nafter swaping the value of a and b ";
s.swp_val();
s.display();
getch();
}
#include<conio.h>
class swap
{
private:
int a,b;
public:
void read()
{
cout<<"\nenter the value of a and b ";
cin>>a>>b;
}
void display(void)
{
cout<<"\nvalue of a = "<<a;
cout<<"\nvalue of b = "<<b;
}
void swp_val(void);
};
void swap::swp_val()
{
a=a+b;
b=a-b;
a=a-b;
}
void main()
{
class swap s;
clrscr();
s.read();
s.display();
cout<<"\nafter swaping the value of a and b ";
s.swp_val();
s.display();
getch();
}
No comments:
Post a Comment