Lab #2 FAQ

(Frequently Asked Questions)

Updated: Sunday, July 19, 1998, at 10:08 AM

Here are some Questions and Answers for Lab #2. I've noticed that students are asking questions similar to these:

****************************************
Q: If the client code attempts to pop from an empty stack, it is an error, and we need to display an error message, but what do we return to the client?

A: It really doesn't matter, but for consistency, you should return 0 or -1, which is typical for functions that must return something even in the case of an error. In this assignment, it is the responsibility of the client to check for an empty stack before popping a value from it.


***************************************
Q: If the client code attempts to "peek" at the top of an empty stack the same problem as above happens. What should we do?

A: Do the same thing as previously mentioned: display an error message and return a value of 0 to the caller.


***************************************
Q: There is a private data member declared as:

  int items[MAX_SIZE];
in the Stack class. Do we need to initialize the array to all zeros or something?

A: No. The reason is that the array represents a Stack, and a stack is initialized by setting top to -1. Since the client has no way of accessing any element of the Stack (array) but the top, it is not necessary to initialize the elements.


***************************************
Q: How many test cases do I need in my driver?

A: That's up to you. I'm grading this assignment on how well you test your implementation. Here's a hint: You are implementing 10 functions in your program, so I would expect at least 10 tests. Although a few functions require more than one test case. I don't want to tell you what to test; by now you should know what needs to be tested. Make sure to follow the instructions I gave. You need to list your tests at the top of your driver code and number them so I can easily locate them. Here is the sample I showed in class.


Back to Outline