Define precondition and post-condition to a member function?



Define precondition and post-condition to a member function?..

Answer / akhilesh kumar jaiswal

Precondition:
A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An operation is not responsible for doing anything sensible if its precondition fails to hold.

For example, the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full. We say that isful() is a precondition of the push operation.

Post-condition:
A post-condition is a condition that must be true on exit from a member function if the precondition was valid on entry to that function. A class is implemented correctly if post-conditions are never false.

For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is the real purpose of class – to export data?

0 Answers  


Write a code/algo to find the frequency of each element in an array?

0 Answers   Axtria,


Write a String class which has: 1) default constructor 2) copy constructor 3) destructor 4) equality operator similar to strcmp 5) constructor which takes a character array parameter 6) stream << operator

2 Answers   HCL, Lehman Brothers, Zoomerang,


What are the differences between a struct and a class in C++?

7 Answers   Amazon, Wipro,


What does ios :: app do in c++?

0 Answers  






Tell me can a pure virtual function have an implementation?

0 Answers  


What is meant by entry controlled loop?

0 Answers   Agilent, ZS Associates,


What is a .h file c++?

0 Answers  


What is pointer in c++ with example?

0 Answers  


What is abstract keyword in c++?

0 Answers  


Implement strcmp

3 Answers   Bloomberg, Citadel,


What is the benefit of encapsulation?

0 Answers  


Categories