Question: How would I add a line to the main function to sort the people vector by Age using the STL sort function? #include #include #include

How would I add a line to the main function to sort the people vector by Age using the STL sort function?

#include  #include  #include  #include  using namespace std; struct Person { string name; int age; string favoriteColor; }; bool sortByName(Person &lhs, Person &rhs) { return lhs.name < rhs.name; } bool sortByAge(Person &lhs, Person &rhs) { return lhs.age < rhs.age; } bool sortByColor(Person &lhs, Person &rhs) { return lhs.favoriteColor < rhs.favoriteColor; } int main() { vector people(5); for (int i = 0; i< 5; i++) { cout << "Person #" << i + 1 << " name: "; cin >> people[i].name; cout << "Person #" << i + 1 << " age: "; cin >> people[i].age; cout << "Person #" << i + 1 << " favorite color: "; cin >> people[i].favoriteColor; } //call STL sort function here! } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!