In today's class we discussed preconditions and postconditions. A precondition states what is assumed to be true when the function is called. A postcondition describes the effect of the function call.
for example:
void swap_values (int&n1, int&n2);
//Precondition: n1 and n2 have been given values
//Postcondition: the values of n1 and n2 have been interchanged
Preconditions and postconditions are helpful because:
1. they specify what a function should do
2. they minimize design errors and time wasted writing code that does not match the task at hand
No comments:
Post a Comment