Page 85 - DCAP404 _Object Oriented Programming
P. 85
Object-oriented Programming
Notes class integer
{
int x;
public:
void getdata()
{
cout << “Enter a value for x”;
cin >> x;
}
void disp()
{
cout << x;
}
void swap(integer *a1)
{
int temp;
temp = x;
x = a1->x;
a1->x = temp;
}
};
main()
{
integer int1, int2;
int1.getdata();
int2.getdata();
cout <<“\n the value of x belonging to object int1 is “;
int1.disp();
cout <<“\n the value of x belonging to object int2 is “;
int2.disp();
int1.swap(&int2);
cout << “\n after swapping “;
cout <<“\n the value of x belonging to object int1 is “;
int1.disp();
cout <<“\n the value of x belonging to object int2 is “;
int2.disp();
cout << “\n”;
getche();
}
78 LOVELY PROFESSIONAL UNIVERSITY