Question: 5.16 LAB: Using the built-in C++ sort() and reverse() functions on a vector of tuples How does the built-in C++ sort() function deal with tuples?

5.16 LAB: Using the built-in C++ sort() and reverse() functions on a vector of tuples How does the built-in C++ sort() function deal with tuples? Which field/attribute does it sort on? To answer this question, you will write a C++ program that • reads in an unknown number of grocery items (each with a name, a unit price, and a quantity) into a vector, • displays the contents of the vector, 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. Additional instructions are provided as instructions in the file main.cpp below... r#include #include #include // for sort, reverse #include #include #include using namespace std; typedef tuplex string, double, unsigned > item; template< typename T > void display( const vector< T > &L ) { string name; double unitPrice; unsigned count; for( auto item: L ) { tie( name unitPrice count ) = item; cout << setw(4) << count << setw(8) << name << setw(6) << setprecision (2) << fixed << unitPrice << endl; } } // DRIVER FUNCTION int main() // STEP 1: Read in an unknown number of grocery items into a vector. // STEP 2: Display the grocery items stored in the vector. // 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. return 0;

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