Question: How does the built-in C++ sort() function deal with a container of structs? The code given below does not compile. The program correctly sets

 

How does the built-in C++ sort() function deal with a container ofstructs? The code given below does not compile. The program correctly setsup a vector of structs but somehow the built-in C++ sart() function

How does the built-in C++ sort() function deal with a container of structs? The code given below does not compile. The program correctly sets up a vector of structs but somehow the built-in C++ sart() function does not know how to compare two structs. What do we need to do? Edit the code given below so that, once completed, you C++ program will read in an unknown number of grocery items (each with a name, a unit price, and a quantity) into a vector [DONE) displays the contents of the vector [DONE] uses the built-in C++ sort() function to sort the vector in ascending order, displays the vector contents in ascending order, uses the built-in C++reverse() function to reverse the contents of the vector, and displays the vector contents in descending order. STEP 1: Read in an unknown number of grocery items into a vector of structs. vector myList; STEP 2: Display the grocery items stored in the vector in the order they were read in. STEP 3: Use the built-in C++ sort() function to sort in ascending order. STEP 4: Display the vector contents in ascending order. // STEP 5: Use the built-in C++ reverse() function to reverse the contents of the vector order they were read in. STEP 3: Use the built-in C++ sort() function to sort in ascending order. STEP 4: Display the vector contents in ascending order. STEP 5: Use the built-in C++ reverse() function to reverse the contents of the vector. /STEP 6: Display the vector contents in descending order.

Step by Step Solution

3.28 Rating (169 Votes )

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 Accounting Questions!