This time let's get technical voyeur Top-Down Ger,, let cool codingnya more .. : D
In addition to using existing information Ger, the programmer can use a top-down design techniques to simplify the development of algorithms and the structure of the resulting program. This time I will show top-down design and emphasizes the role of modular programming using functions for all of us ..
check!!!
A. Building Programs from Existing Information
Programmers rarely start with a blank sheet of paper (or a blank screen) when they developed the program. Systems-thinking document, which comprises a description of the data requirements of these problems (developed during the analysis phase) and a solution algorithm (developed during the design phase), summarizes your intentions and thought processes. You can use this document as a starting point in the coding of your program.
Function Library
A. Predefined Functions and Code Reuse
The main purpose of software engineering is to write error-free code. Code reuse, reus-ing program fragments that have been written and tested, if possible, is one way to achieve this goal.
C standard math library defines a function named sqrt who calculate square roots. Function call in the assignment statement
y = sqrt (x);
first_sqrt = sqrt(first);
second_sqrt = sqrt(second);
sum_sqrt = sqrt(first + second);
C. Library Functions
Top-Down Design and Structure Charts
Functions without Arguments
One way that programmers implement top-down design in their programs is by defining their own functions. Often, a programmer will write one function subpro- gram for each subproblem in the structure chart.
1. Function Prototypes
3.Placement of Functions in a Program
Program Style
Use of Comments in a Program with Functions
Figure 3.14 includes several comments. Each function begins with a comment that describes its purpose. From now on throughout this text, the block comment and heading of each function definition are in color to help you locate functions in the program listing.
Order of Execution of Function Subprograms and Main Function
Because the prototypes for the function subprograms appear before the main func- tion, the compiler processes the function prototypes before it translates the main function. The information in each prototype enables the compiler to correctly translate a call to that function.
Advantages of Using Function Subprograms
There are many advantages to using function subprograms. Their availability changes the way in which an individual programmer organizes the solution to a programming problem.
procedural abstraction
a programming tech- nique in which a main function consists of a sequence of function calls and each function is implemented separately
Displaying User Instructions
The simple functions introduced in this section have limited capability. Without the ability to pass information into or out of a function, we can use functions only to display multiple lines of program output, such as instructions to a program user or a title page or a special message that precedes a program’s results.
Functions with Input Arguments
Programmers use functions like building blocks to construct large programs. Functions are more like Lego® blocks ( Fig. 3.17 ) than the smooth-sided wooden blocks you might have used as a young child to demonstrate your potential as a budding architect. Your first blocks were big and did not link together, so buildings over a certain size would topple over. Legos, in contrast, have one surface with lit- tle protrusions and one surface with little cups.
0 comments:
Post a Comment