Homework 2 FAQ

EECS380 Winter '01

This document is to add some additional explanations as to what Homework 2 is asking you to do. The main document is actually quite complete and precise, this document simply strives to clarify some of the possibly confusing aspects and to provide a bit of coding guidance.
  1. What exactly are we doing in part 1?

    You are to create two different classes. Both of these classes are simply ways of storing a list of doubles. One class uses an array, the other uses a linked list. The classes each provide reader and writer functions.


  2. What is pretty print supposed to do?

    Print out all the doubles in the list. Ideally in a ``pretty'' way and in a way. It must be clear what the ordering is inside of the list. You have a lot of flexibility in the implementation of this function.


  3. I have no idea how to write the function double& operator[](unsigned idx); or why you would want to.

    Suppose you have

        class X
        {
          double data[100];
          public:
             double& operator[](unsigned idx) { return data[idx]; }
        };
    
    then you can write
          X x;
          x[1]=-1.2345;
          x[2]=x[1]+100;
    
    and so on. If you happen to forget the & sign, the lines starting with x[1] and x[2] won't compile. Instead of that one operator, you could do something like
        double getValueByIndex(unsigned idx) const { return data[idx]; }
        void   setValueByIndex(unsigned idx, double val) { data[idx]=val; }
    
    then the four lines above would look like this:
          X x;
          x.setValueByIndex(1,-1.2345);
          x.setValueByIndex(2,x.getValueByIndex(1)+100);
          cout << x.getValueByIndex(2) << endl;
    
    which one looks more better/easier ? :)

    Also, example 24 at this C++ site provides some insight on the issue.


  4. Can I use the multi-argument constructors to correctly initialize the lists in part 3?

    Nope. Those multi-argument constructors (EECS380_DynContainer(unsigned maxSize, unsigned size, double val) for example) require initializing `size' values to the same value. Not what is wanted for part 3.


  5. Gosh, isn't this a long and hard homework?

    Not really. We gave a few extra days (and some extra points) because the instructors felt it was pretty long for 2% of your grade. But it really shouldn't take that long. After all:


  6. What has changed on hw2 since it was first handed out?


For the record, the Due date is Feb 6th at 6pm. It is worth twice the points of a normal homework (4% of your class grade!).