1.

Explain precondition and postcondition to a member function in the context of C++ programming language.

Answer»

A precondition is a condition that must be met before a member FUNCTION may be called. If PRECONDITIONS are never false, a CLASS is appropriately used. If a precondition fails to hold, the following function is not executed. For EXAMPLE, before inserting an element into a stack, we call the isfull() to check if the stack is full or not. Here, the isfull() is an example of a precondition.

A post-condition is a condition that must be true when a member function is exited if the precondition was true when the function was entered. For a code to be correctly implemented, the post-conditions must never be false For example, we know that isempty() must always hold after placing an element ONTO the stack. This is a push operation post-condition.



Discussion

No Comment Found