Homework: Standard Template Library

  < Previous  Next >

For this homework assignment, submit a copy of hwkStl.cpp.
  1. Add code so that for each of the STL sequence and adaptor container:
    1. The number of elements in the container is printed (using a container method if possible)
    2. The contents of the container are printed out (in the reverse order that they were read in) using only that container type and possibly a loop index (int) variable (do not use iterators yet :)
      • If this is not possible for a particular container, print out why it is not possible and (if possible) the contents of the container
  2. Can the number of elements and the contents be printed out in the order that they were entered for associative containers? Why? (answer by printing out the answer below the question in the code)
  3. Add in code to print out the contents of the containers (in the order that they were entered) using STL iterators
    • If this is not possible for a particular container, print out why it is not possible and (if possible) the contents of the container
  4. Determine the unique elements in the vector (using STL algorithms) and print them out
Your copy needs to compile on ranger using the following command-line:
g++  -std=c++0x  hwkStl.cpp
Given STDIN like what is in hwkStl-stdin.txt:
9 8 7 6 5 5 7 9 a
your code needs to produce output that matches (but not necessary exactly) what's in hwkStl-stdout.txt:
---------------------- STL vector ----------------------
Enter numbers to store in STL containers (enter a letter to stop)
There are 8 integers in the vector
9
7
5
5
6
7
8
9
---------------------- STL array ----------------------
There are 11 elements in the array
...

Submission

Submit your cpp file at https://3110.cs.mtsu.edu/. For further instructions, please see the Miscellaneous page.

Rubric:

Points          Item
----------      --------------------------------------------------------------
_____ /  4      1. Declaring containers, adding elements and printing the number of elements and their values in reverse order (if possible) 
_____ /  1      2. Associative containers question
_____ /  2      3. Iterators to print out values (in the order that they were entered)
_____ /  3      4. Determine the unique elements using STL algorithms

_____ / 10      Total
      

Notes

  1. You should verify that your output matches the above output (with a few exceptions) with the following commands on ranger:
    g++  -std=c++0x  hwkStl.cpp  -o hwkStl-yourlastname
    ./hwkStl-yourlastname  <  /nfshome/hcarroll/public_html/3110/private/hwk/hwkStl-stdin.txt  &>  hwkStl-yourlastname.txt
    diff  /nfshome/hcarroll/public_html/3110/private/hwk/hwkStl-stdout.txt  hwkStl-yourlastname.txt

Hints

  1. If you can not get a part of the code to work, comment it out and move on to maximize the number of points earned.
  2. It IS possible to print out the contents in the reverse order that they were read in for all but one of the sequence and adaptor containers. You may want to use more than one instantiation of the particular container.
  3. You can assume that there will be less than 11 numbers in the input.

Last Modified: