Hello, I just started learning C++ and I have to make a program that says who is the oldest person from a list of persons. I made a class Pers where i defined the class destructor, name and age but I don't know how to compare the age of all the persons in the list. Can somebody give me some advice? The class i created looks like this:
1 2 3 4 5 6 7 8 9 10 11
class Pers
{
public:
Pers(char *bname, int bage);
int age;
char name[200];
};
Pers::Pers(char *bname,int bage)
{ strcpy(Pers::name, bname);
Pers::age=bage;}
Rather than use char arrays I would suggest that you use std::string and then as a container of the Person instances you use a std::vector, then you can use the std::sort:
Keep in mind that the word 'array' is not solely in the domain of C-style char arrays and vectors are not the sole domain of the rather wider range of C++ STL containers also capable of sorting!