202. Write a program to show the use of this pointer?

#include<iostream.h>
#include<conio.h>
class number
{
                int a;
public:
                void get()
                                {
                                cout<<"Enter A Number : ";
                                cin>>a;
                                }
                number check(number num)
                                {
                                if(num.a>a)
                                                {
                                                return num;
                                                }
                                else
                                                {
                                                return *this;
                                                }
                                }
                void display()
                                {
                                cout<<"The Large Number Is : "<<a<<endl;
                                }
};
void main()
{
                clrscr();
                number n,n1,n2;
                n1.get();
                n2.get();
                n=n1.check(n2);
                n.display();
                getch();
}

202.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: