The basic course of C language (VI) Turbo C programming Preliminary (2)
Source: Internet
Author: User
Step two: Draw the basic outline of the program
In this step, you will use some sentences (pseudocode) to draw the basic outline of the program. Each sentence corresponds to a simple program operation. For a simple program, the pseudocode can be generated directly by listing the actions executed by the program sequence. However, for complex programs, the general process needs to be organized in a structured way. In this respect, the Top-down design approach should be used.
When using a top-down design approach, you have to split the program into segments to complete. Lists the tasks to be implemented in each paragraph, and the outline of the program is called the main module. When a task is listed in the main module, it is identified by its name only and does not indicate how the task will be completed. This content is left to the next stage of the program design to discuss. Dividing a program into several tasks is just a preliminary design of the program. The whole program comes down to the flowchart shown in the following figure 1.
┏━━━━━━━━━━━━━━━┓
┃ Main module ┃
┏━━━━━━━┓┃ input Data ┃
┃ Main module ┃┃ calculate the amount of purchase required ┃
┃┃┃ calculate the amount of decoration required ┃
┃ task 1┃┃ Calculate total Amount ┃
┃ task 2┃┃ Output calculation Results ┃
┃ Task 3┃┃┃
┃ Task 4┃┗━━━━━━━┳━━━━━━━┛
┃┃┏━━━━━┳━━━━━╋━━━━┳━━━━━┓
┃┃┏━━┻━┓┏━━┻━┓┏━━┻━┓┏━┻━┓┏━━┻━┓
┗━━━━━━━┛┃ input data ┃┃ purchase amount. ┃┃ Decoration Amount ... Total ┃┃. ┃┃ Output Results ┃
┗━━━━┛┗━━━━┛┗━━━━┛┗━━━┛┗━━━━┛
Figure 1. Program preliminary design Figure 2. Second level programming
If you extend each task of the main module into a module and define it according to subtasks, then the program is more detailed (see Figure 2.). These modules are called child modules of the main module. The relationship between many of the child modules in the program can be summed up in a graph as shown in Figure 2. This diagram is called a structural diagram.
To draw the outline of the module, you don't have to consider the details. If so, you must use the Sub module, the various modules refinement, to achieve the third level of design. Continue this process until the full details of the procedure are explained. This level of design process is called progressive refinement. Before writing a program, the gradual refinement of your program, for you, is a good program design practice, will enable you to develop good design habits.
We then described the Top-down design approach in programming. In fact, we are designing programs that start with the "Top" of the program and always consider the "bottom" of the program.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service