# 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;
public:
double& operator[](unsigned idx) { return data[idx]; }
};
```
then you can write
```      X x;
x=-1.2345;
x=x+100;
```
and so on. If you happen to forget the & sign, the lines starting with x and x 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:

• You do have a lot of functions to write. However, most should be less than 3 lines of code. Not too bad.
• We have covered a lot of this stuff in class in detail. Nothing should be all that new.
• Many of you did similar things for projects in EECS280.

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

• A few typos were fixed.
• It was made clear that you should not try to plot widely different values on the same graph.
• The due date and value of the assignment were changed.
• A suggestion was added (before the turn-in check-list) to compile/run everything in two ways: with -g and with -O3. The latter tells the compiler to optimize code for speed.
• A clarification was added to Part 4, that the interfaces in part 1 can be extended. For example, cloning double& operator[] (unsigned idx) into double operator[](unsigned idx) const should be sufficient for the array-based container.
• Set-difference in Part 4 must run in linear time, which is why adding double operator[](unsigned idx) const won't be enough for the linked list.

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!).