Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions