Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

9-4 List steps to take in the appraisal interview.

Answered: 1 week ago