Monday, 13 April 2020

Write a program to maintain the records of person with details (Name and Age) and find the eldest among them.

Write a program to maintain the records of person with details (Name and Age) and find the eldest among them. The program must use this pointer to return the result. 



#include<iostream.h>
#include<string.h>
class person

char name[20]; 
float age;
public: 
person(char *s, float a) 

strcpy(name, s); 
age = a; 
}
person & person :: greater(person & x) 

if(x.age >= age)   
return x; 
else   
return *this; 
}
void display(void) 

cout<<"Name:"<<name<<"\n"    <<"Age: "<<age<<"\n"; 
}
};
int main()

person p1("John", 37.50),     
p2("Ahmed",29.0),     
p3("Hebber", 40.5);
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;
}

No comments:

Post a Comment