Starting from:
$35

$29

STL2 Solution

For this in-class assignment, make use of the STL to perform a few operations on a list of numbers. You can do everything in the main function. Please use the deque STL container and STL algorithms to do the following:
 


    1. Insert the numbers 3, 4, 6, 2, 9, 1, 5, 0, 7, 8 by inserting the numbers in that order, one at a time, to the end of the deque. 
 


    2. Use STL algorithms to remove the value of 7 from the deque.(hint: you will need to use both the remove algorithm and erase function of the container)

    3. Use STL algorithms to replace values greater than 6 in the deque with 10.

    4. Use STL algorithms to return the sum of all the elements in the deque and print out the sum. Then insert that sum to be a new element at the beginning of the deque.

    5. Use STL algorithms to count the number of elements in the deque that are greater than 6 and print out the count.

    6. Use STL algorithms to output the half (integer division) of every element in the deque. (Do not modify the elements in the deque.)

    7. Use STL algorithms to sort the deque.
 


    8. Use the STL algorithms to find the location of 6 in the deque and print out the location.
 


    9. Use the ostream_iterator and the copy algorithm to print out the deque elements with a comma in between the numbers. The last element can also have a comma after it. Make sure you make use of STL algorithms. Please don't use loops or access the deque elements by using the subscript operator (such as using values[1]).

You may use the lecture sildes and online c++ references. All of the functions necessary to do these operations should be in the lecture powerpoint slides.

Your sample output should be:
 


The sum of the numbers 0 to 9 after removing 7 and replacing values greater than 6 with 10 is: 41

Now the number of elements greater than 6 is: 3

The half of every element in the deque is:    20 1 2 3 1 5 0 2 0 5 


After sorting, the location of 6 is at index: 6


The items in the deque are: 0, 1, 2, 3, 4, 5, 6, 10, 10, 41,
 Press any key to continue . . .




You may want to use (but not limited to) these pages: http://www.cplusplus.com/reference/deque/ http://www.cplusplus.com/reference/algorithm/ http://www.cplusplus.com/reference/iterator/

More products