/*C++ program to illustrate the usage of this pointer*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<conio.h>
#include<string.h>
class person
{
char name[20];
float age;
public:
person(char *s,float a)
{
strcpy(name,s);
age=a;
}
person(char *s,float a)
{
strcpy(name,s);
age=a;
}
person &person::greater(person &x)
{
if(x.age>=age)
return x;
else
return *this;
}
{
if(x.age>=age)
return x;
else
return *this;
}
void display()
{
cout<<"Name: "<<name<<"\nAge: "<<age<<endl;
}
{
cout<<"Name: "<<name<<"\nAge: "<<age<<endl;
}
};
void main()
{
clrscr();
person p1("John",37.50),p2("Ahmed",29.0),p3("Heffer",40.25);
person p=p1.greater(p3);
cout<<"Elder person is:\n";
p.display();
p=p1.greater(p2);
cout<<"Elder person is\n";
p.display();
{
clrscr();
person p1("John",37.50),p2("Ahmed",29.0),p3("Heffer",40.25);
person p=p1.greater(p3);
cout<<"Elder person is:\n";
p.display();
p=p1.greater(p2);
cout<<"Elder person is\n";
p.display();
getch();
}
}
OUTPUT:
Elder person is:
Name: Heffer
Age: 40.25
Name: Heffer
Age: 40.25
Elder person is
Name: John
Age: 37.5
Name: John
Age: 37.5