#include <iostream>
#include <cstring>
using namespace std;
class Person
{
char name[20];
int age;
public:
Person(char *s, float b)
{
strcpy(name,s);
age=b;
}
Person & greater(Person &y)
{
if(y.age>age)
return y;
else
return *this;
}
void display()
{
cout<<"Name: "<<name<<endl;
cout<<"Age : "<<age<<endl;
}
};
int main()
{
cout<<"Program on this pointer\n";
Person P1("Kailas",49);
Person P2("Rajesh",51);
Person P3("Sunil",40);
Person P=P1.greater(P3);
cout<<" Elder person is: \n";
P.display();
P=P1.greater(P2);
cout<<" Elder person is: \n";
P.display();
return 0;
}
output:
Program on this pointer
Elder person is:
Name: Kailas
Age : 49
Elder person is:
Name: Rajesh
Age : 51
0 Comments
Post a Comment