Dynamic Stack  «Prev  Next»

Adding C++ Constructor to a Stack - Exercise

Objective: Add a constructor to the class ch_stack based on a given function prototype.

Instructions


Use the following prototype to add a constructor for ch_stack:
ch_stack::ch_stack(const char* c);

The constructor will initialize the stack from a string array. Paste the source code of your program below and click the Submit button when you are ready to submit this exercise.

Improper inheritance

Improper inheritance is a very common design error. This seems to be because developers base inheritance relationships on their intuition rather than the objective criteria of substitutability. The following inheritance relationships are improper because the derived class either requires more or promises less.
  1. A Stack is not a kind-of List (assuming List provides member functions that allow insertions in the middle of the list and Stack does not).
  2. A ListOfApples is not a kind-of ListOfFruit (assuming that any type of Fruit can be put into a ListOfFruit).
The following inheritance relationships may or may not be proper inheritance depending on the specified behavior of the base class and the derived class.
  1. A Circle may not be a kind-of Ellipse.
  2. An Ostrich may not be a kind-of Bird.
  3. An Integer may not be a kind-of RationalNumber.