to know what the function does, and not how it is done by the function. The function can be used a a "black box" in solving other problems. Ultimately, someone implements the function using an algorithm. However, users of the function need not know about the algorithm used to implement the function.
It is hidden from the users. There is no need for the users to know how the function is implemented in order to use it. An algorithm used to implement a function may maintain its own variables. These variables are local to the function in the sense that they are not visible to the user of the function.
Consequently, the user has fewer variables to maintain in the main algorithm, reducing the clutter of the main algorithm. Example . . Consider the problem of testing whether a triangle is right-angled, given its three sides a, b, c, where c is the longest side.
The triangle is right-angled, if c = a + b We can identify a subproblem of squaring a number. Suppose we have a function square(), specified as square(y) -- inputs : y -- outputs : y Chapter Page - - we can use this function three times to test whether a triangle is right-angled. square() is a "black box" — we need not know how the function computes the square. We only need to know its specification.
y Square y Figure . : square function Points to Remember • Compound statements are composed of sequential, alternative and iterative control flow statements. • The value of a condition is true or false, depending on the values of the variables. • Alternative statement selects and executes exactly one of the two statements,depending on the value of the condition.
• Conditional statement is executed only if the condition is true. Otherwise, nothing is done. • Iterative statement repeatedly evaluates a condition and executes a statement as long as the condition is true. • Programming language, pseudo code, and flowchart are notations for expressing algorithms.
• Decomposition breaks down a problem into