Topical Information

This lab will help you practice with 2D vectors.

Program Information

Write a program to solve problem 14 from page 565 of chapter 10. Don't forget to adjust for the author's poor style (int, return's, commenting, etc.).

Alter the input so that you can fill in only the number of values in the production vector as you need. (That way when that new plant comes online next month, we won't have to re-compile with a new constant. I hear another is scheduled for construction by the end of the year, too!)

You can label the graph something like this:

                   *
                   *
                   *
                   *
                   *    *
                   *    *
                   *    *
                   *    *
         *    *    *    *
         *    *    *    *
         *    *    *    *
         *    *    *    *
         *    *    *    *
         *    *    *    *
Plant    1    2    3    4

(That'd be the one from the book sample run...)

Thought Provoking Questions

  1. How will a 2D vector help you graph a histogram like this? (Either horizontal or vertical...) I.E. How does a 2D vector relate to the graph you see on the screen? (What would the base-type of the vector be?)

  2. How do you initialize your graph vector? What should be the default element value? (Other than the graph, what is there?)

  3. If you had a function designed like this:

        // Fills in the vector from index min to index max (max not included)
        // with the specified value.
        void fill_vector(vector<_TYPE_> vec, _TYPE_ with,
                         vector<_TYPE_>::size_type max,
                         vector<_TYPE_>::size_type min = 0);
    
    Would that help you draw the initial graph?

    (Could this also help with the initialization discussed above?)

  4. How can you rotate a horizontal graph into a vertical graph? Does vector traversal order have anything to do with this? (i.e. Row-by-row vs. Column-by-column..? Ooo...Right-to-Left...Top-to-Bottom...etc.)

This assignment is (Level 4).

Options

Add (Level 1.5) to label the graph columns horizontally under the graph. Try to center the column above the label. It might look something like this:

                       *
                       *
                       *
                       *
                       *         *
                       *         *
                       *         *
                       *         *
   *         *         *         *
   *         *         *         *
   *         *         *         *
   *         *         *         *
   *         *         *         *
   *         *         *         *
Plant 1   Plant 2   Plant 3   Plant 4

Add (Level 2.5) to label the graph columns vertically under the graph -- one letter per line. This might look like:

             *
             *
             *
             *
             *    *
             *    *
             *    *
             *    *
   *    *    *    *
   *    *    *    *
   *    *    *    *
   *    *    *    *
   *    *    *    *
   *    *    *    *
----------------------
   P    P    P    P
   l    l    l    l
   a    a    a    a
   n    n    n    n
   t    t    t    t

   1    2    3    4

(You can do both this and the previous option by letting the user choose the labeling style with a menu. I'll even throw in another (Level 0.5) for the trouble to make the menu decent.)