Modular programming and Modules
Modular programming is breaking down the design of a program into individual
components (modules) that can be programmed and tested independently. It is a
requirement for effective development and maintenance of large programs and
projects. With modular programming, procedures of a common functionality are
grouped together into separate modules. A program therefore no longer consists
of only one single part. It is now divided into several smaller parts which interact
and which form the whole program.
Definition of Functions
Modules in C++ are called functions. A function is a subprogram that can act on
data and return a value. Every C++ program has at least one function, main().
When your program starts, main() is called automatically. main() might call other
functions, some of which might call still others. Each function has its own name,
and when that name is encountered, the execution of the program branches to
the body of that function. When the function returns, execution resumes on the
next line of the calling function. When a program calls a function, execution
switches to the function and then resumes at the line after the function call. Welldesigned functions perform a specific and easily understood task. Complicated
tasks should be broken down into multiple functions, and then each can be
called in turn. Functions come in two varieties: user-defined and built-in. Built-in
functions are part of your compiler package--they are supplied by the
manufacturer for your use. In this chapter we will discuss about user-defined
functions.
1/1
| Term | Definition |
|---|---|
Modular programming and Modules
Modular programming is breaking down the design of a program into individual
components (modules) that can be programmed and tested independently. It is a
requirement for effective development and maintenance of large programs and
projects. With modular programming, procedures of a common functionality are
grouped together into separate modules. A program therefore no longer consists
of only one single part. It is now divided into several smaller parts which interact
and which form the whole program.
Definition of Functions
Modules in C++ are called functions. A function is a subprogram that can act on
data and return a value. Every C++ program has at least one function, main().
When your program starts, main() is called automatically. main() might call other
functions, some of which might call still others. Each function has its own name,
and when that name is encountered, the execution of the program branches to
the body of that function. When the function returns, execution resumes on the
next line of the calling function. When a program calls a function, execution
switches to the function and then resumes at the line after the function call. Welldesigned functions perform a specific and easily understood task. Complicated
tasks should be broken down into multiple functions, and then each can be
called in turn. Functions come in two varieties: user-defined and built-in. Built-in
functions are part of your compiler package--they are supplied by the
manufacturer for your use. In this chapter we will discuss about user-defined
functions. |