Code Competitions

Coding competition
Showing posts with label swaping using class. Show all posts
Showing posts with label swaping using class. Show all posts

Wednesday, 12 June 2013

program to swap numbers using class

#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();
}