Saturday, September 27, 2014

Create a class person with its necessary data members and member function. Create a member function that compares the age of person and returns the person having greater age by the use of ‘this’ pointer.

#include
#include
class person
{
            int age1,age2,age;
            public:
            void input()
            {
                        cout<<"\nEnter two ages:";
                        cin>>age1>>age2;
            }
            void show()
            {
                        cout<age<<"is greater.";
            }
            int check()
            {
                        if(age1
                        return this->age=age2;
                        else
                        return this->age=age1;
            }
};
int main()
{
            clrscr();
            person p;
            p.input();
            p.check();
            p.show();
            getch();
            return 0;
}

No comments:

Post a Comment