Question

In: Computer Science

C++ Have the user type in 10 numbers. Then, using STL STACKs print a table showing...

C++

Have the user type in 10 numbers. Then, using STL STACKs print a table showing each number followed by the next large number. For example, if the user types the following

7 5 12 25

The output should be this:

Element       Next Greater Number
   5      -->   7
   7      -->   12
   12     -->   25
   25     -->   -1

You can use this functor to sort the vector:

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct greater
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};

int main()
{
vector <int> v = { 1,4,2,6 };
sort(v.begin(), v.end(), greater());
return 0;
}

Solutions

Expert Solution

// PLEASE GIVE ME +VE RATING.

// YOUR RATING IS IMPORTANT FOR ME.

// THANKS.


Related Solutions

Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a program that will print the whole numbers from a user-specified minimum to a user-specified...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
USING a LOOP for C++ In this lab the completed program should print the numbers 0...
USING a LOOP for C++ In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and by 10....
write a program that will print a truth table for p ^ ~q. Using C++ please.
write a program that will print a truth table for p ^ ~q. Using C++ please.
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
Below is a table showing the production numbers for a chair factory (where the production numbers...
Below is a table showing the production numbers for a chair factory (where the production numbers are based on chairs being produced per day). Workers Total Product (TP) Average Product (AP) Marginal Product (MP) Value of the Marginal Product (VMP) 0 0 - - - 1 20 2 60 3 40 4 180 5 46 6 270 7 300 8 40 9 10 10 5 a) Fill in the missing numbers for the TP, AP and MP columns (round to...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a C++ class that implement two stacks using a single C++ array. That is, it...
Write a C++ class that implement two stacks using a single C++ array. That is, it should have functions pop_first(), pop_second(), push_first(…), push_second(…), size_first(), size_second(), …. When out of space, double the size of the array (similarly to what vector is doing). Notes: Complete all the functions in exercise_2.cpp, then submit this cpp file. pop_first() and pop_second() should throw std::out_of_range exception when stack is empty. CODE: #include <cstdio> #include <stdexcept> template <class T> class TwoStacks { public:   // Constructor, initialize...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a...
Create a C++ program using native C++ (STL is acceptable) that produces Huffman code for a string of text entered by the user. Must accept all ASCII characters. Provide an explanation for how you got frequencies of characters, how you sorted them, and how you got codes.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT