Jumat, 22 Maret 2013

Top-Down Design with Functions


Programers use software development methods to solve the problem. Normally, programmers handle every new program as a unique event.

Building programs from existing information

Develop your program solutions from existing information. Use the system documentation derived from applying the software development method as the initial framework for the program.
  • Edit the data requirements to obtain the main function declarations. 
  • Use the refined algorithm as the starting point for the executable statements in the main function.
If a new problem is an extension of a previous one, modify the previous program rather than starting from scratch.

Library Function

Use C’s library functions to simplify mathematical computations through the reuse of code that has already been written and tested. Write a function call (consisting of the function name and arguments) to activate a library function. After the function executes, the function result is substituted for the function call.

Top-Down Design and structure charts

Use a structure chart to show subordinate relationships between subproblems. Utilize modular programming by writing separate function subprograms to implement the different subproblems in a structure chart. Ideally, our main function will consist of a sequence of function call statements that activate the function subprograms.

Function without Argument

We can write functions without arguments and results to display a list of instructions to a program user or to draw a diagram on the screen. Use a function call consisting of the function name followed by an empty pair of parentheses () to activate such a function.

Prototype Function

Just like other identifiers in C, the function must be declared before it can be referenced. One way to declare a function is to insert the function prototype before the main function. A function prototype tells the compiler the C data type of the function, the function name, and information about the argument. The data type of a function is determined by the type of the value returned by the function.

Definition Function

Although in making the function prototype to determine the number of arguments take time, but it did not specify the operating functions. To do this, you need to provide a definition for each function subprogram is similar to the definition of the main function.

Advantages of using subprogram Functions

There are many advantages to using a function subprogram. Being able to change the way in which a programmer create solutions to solve programming problems. For a team of programmers, subprogram facilitate the programming is completed by dividing Carau programming tasks. Each programmer will be responsible for a set of specific functions.

Displays User Instruction

Simple functions introduced in this section that have limited capabilities. Without the ability to pass information into or out of a function, we can use the function just to show a few lines of the output of the program, such as instructions to the user program or the title page or a special message that precedes the results of the program.


Function with input Argument

Write functions that have input arguments and that return a single result to perform computations similar to those performed by library functions. When we call such a function, each actual argument value is assigned to its corresponding formal parameter. Place prototypes (similar to function headings) for each function subprogram before the main function, and place the function definitions after the main function in a source file. Use (void) to indicate that a function has no parameters.

Tidak ada komentar:

Posting Komentar