Implement a class Person with the following data members:
• name (string) - name of this person
• age (integer) – age of this person
Write a program that reads in a list of names and ages and stores them in a one-dimensional array of Person objects. The maximum number of names that will be entered is 100 names. After reading in the list of names and ages, sort the list of people from the youngest (lowest age) to oldest (highest age). Then print out the name and age for each person in the sorted list.
I have the code that I have posted below so far. I am getting one error in my int main() for an Expected unqualified- id. Not sure what exactly that means and how to go about fixing it. Any help, hints, or suggestions would be greatly appreciated.
string name; //name of the person ??
int age; //age of the person ??
static const int arrSize = 100; //how many names
int arrAge[arrSize]; //age of the person - array
string arrName[arrSize]; //name of the person - array
name = " ";
age = 0;
for (int s=0; s < arrSize; s++)
cout << "Enter name (-1 to stop): ";
cin >> arrName[s];
//if (arrName[s] == -1)
cout << "Enter age of " << arrName[s] << ": ";
cin >> arrAge[s];
} //end for
Person is the type name, person is the object name. To call a member function, you need to provide the name of an object.
1 2 3 4 5
hints, or suggestions
Don't use arrays. In this case, use a map<string, age> or a vector of pairs (so you can sort it the way you need), or even a multimap<age, string> so the compiler sorts for you.
Don't forget to uncomment your "-1" check. (and use "-1", not -1 there)
Use member initializers in your constructors