|
Lesson 6FUNCTION: ORGANIZING THE PROGRAMAs problems grow they become more difficult to solve. One problem solving strategy is to break a problem into smaller problems (sub-problems) then solve each of the sub-problems separately. This idea of breaking a big problem into smaller ones is reminiscent of the old expression divide and conquer. Similarly, a big program can be broken into subprograms that can be written and tested independently. Each of these subprograms is known as a function (unit) with a specific action (task) to perform. Normally, an application program (software) consists of thousands of lines of code (instructions). Without an organization (function), it is almost impossible to write, test, use, maintain, or reuse a large program. Can you imagine a team of programmers trying to write and manage a program without using functions? TWO KINDS OF FUNCTIONSThere are two kinds of functions: built-in functions and user-defined functions. A built-in function is pre-constructed and is available for use in your program. A user-defined function must be built by the programmer. C/C++ BUILT-IN FUNCTIONSC/C++ comes with a library of functions that are pre-programmed and ready for use in your program. You are already familiar with the C built-in functions scanf(...),
and printf (...), and the C++ function eof (...).
|
This
information was powered by
Prof A, Ebrahimi