ch_stack (Exercise)Objective: Add a constructor to the class ch_stack based on a supplied function prototype.
In this module you’ve been constructing a dynamically sized stack. In earlier lessons you added constructors for capacity and copying. In this exercise, you’ll add a string-initializing constructor so a stack can be created directly from a C-string.
Use the following prototype to add a constructor for ch_stack:
ch_stack::ch_stack(const char* c);
const char*).c is nullptr (treat as an empty initialization).nullptr over NULL.ch_stack stores characters in a buffer, compute the input length with std::strlen (guarding against nullptr), then copy only what fits.std::string_view in addition to const char*. (Keep the required prototype for this exercise.)This module focuses on class construction and ownership, but design still matters. A common OO mistake is choosing inheritance where composition is required. For example, a Stack is not generally a subtype of a List if the list interface allows operations (like inserting in the middle) that violate stack semantics.
The following relationships may or may not be valid depending on the contracts involved:
Next, the exercise result page will display your submission and (optionally) provide guidance on the constructor’s correctness
and edge cases (such as nullptr input and capacity limits).