Traditional Culture Encyclopedia - Traditional stories - How to draw the program flow chart?

How to draw the program flow chart?

It is an excellent method to express the idea of the algorithm with graphics in the flow chart, because a thousand words are not worth a picture. What is the drawing method of program flow chart? I have compiled some information for you, I hope you like it!

First, grasp the characteristics

The three elements of any program block diagram are "four frames", "one line" and "text description", so we should first grasp their respective characteristics and significance.

The characteristics and significance of "four boxes": ① The starting box and ending box of the junction box * * * * are rounded rectangles, indicating the beginning and end of the algorithm, which is indispensable for any process; ② The input-output box is characterized by parallelogram, which represents the input and output of information in the algorithm, and can be placed at any position where input and output are needed; (3) The processing box * * * The execution box * * is characterized by a square rectangle, indicating assignment and calculation. The data or calculation to be processed in the algorithm can be written in different processing boxes; The feature of the judgment box is a diamond, which is used when the algorithm needs to judge two different results.

Characteristics and significance of "one line": The pipeline is characterized by a line with a directional arrow, which is used to connect the program framework and visually represent the flow of the algorithm. There is a streamline between any two program frames.

Features and meanings of words: The words and expressions explained in the block diagram are also indispensable contents of each block diagram.

Second, clear rules.

The drawing rules of program block diagram are as follows: ① use standard, that is, use standard block diagram symbols; (2) In sequence, that is, the block diagram is generally drawn from top to bottom and from left to right; (3) Look at the discrepancy, that is, most graphic symbols in the program block diagram only have one * * * and one exit, and the judgment box is the only symbol with more than one exit, and the exit should be marked with "Yes" or "No" in the conditional structure; (4) open loop, that is, the initial value of variables and loop termination conditions should be paid attention to in the loop structure; ⑤ Distinguish the flow direction, that is, the arrow of the flow line indicates the execution direction, which is indispensable; ⑥ Brief description, that is, the description language in graphic symbols should be concise and clear.

Third, follow the steps

The general steps of drawing a program block diagram are: first, design the algorithm, because the design of the algorithm is the basis of drawing a program block diagram, so before drawing a program block diagram, write the corresponding algorithm steps, and analyze what kind of basic logic structure * * * sequence structure, conditional structure, loop structure * * and so on are needed for the algorithm; The second step is to transform the algorithm steps into the corresponding program block diagram. In this transformation process, many details often need to be considered, which is a process of "refining" the algorithm. Please refer to the example for specific drawing steps.

Example 1 A shopping mall offers a preferential promotion: if the shopping amount X is above 500 yuan, it will be 20% off; If the shopping amount X is above 300 yuan, get a 10% discount; Otherwise there is no discount. The program block diagram of the algorithm is designed, and the actual payment can be output by inputting the purchase amount X.

Algorithm analysis: according to the meaning of the question, what is the functional relationship between the actual payment amount Y and the shopping amount X? x,x≤300? y=? 0.9x,300 & ltx≤500? 0.8x,x & gt500? Because X needs to be judged three times, the algorithm contains two conditional structures. The steps of writing the algorithm are as follows: Step one, input the shopping amount X. 。

The second step is to judge whether x is less than or equal to x≤300. If so, y = x;; Otherwise, enter the third step. Step 3, is it judged that X is less than or equal to x≤500? If yes, y = 0.9x or y = 0.8x. Step 4, output y and end the algorithm.

Drawing steps: ① Draw a sequence structure diagram, that is, the start-stop box and the input box, and connect * * * with streamline as shown in Figure ① * * *; (2) draw a conditional structure diagram, that is, draw a judgment box and

Judge x≤300? If yes, draw a processing box and fill it in.

"y=x", otherwise it will flow to the next judgment box * * * as shown in the figure.

②***; (3) draw a conditional structure diagram, that is, draw a judgment box and merge it.

Judge x≤500? If so, draw a processing box.

"y=0.9x", otherwise draw the processing box "y=0.8x"

* * * As shown in Figure ③ * * *; ④ Draw a general output box and output it.

Y, the start-stop box indicates the end of the algorithm * * *, as shown in Figure ④ * * *.

Finally, the block diagram of the algorithm is shown in figure 1.

Comments: The key to drawing program block diagram is to analyze algorithm steps. Because the program block diagram is a graphical representation of algorithm steps, the clearer the algorithm steps are, the easier it is to draw. In addition, conditional structures, such as piecewise functions, should be used in the algorithm design that needs to judge conditions.

Example 2 if1+3+5++n >; In 2008, I tried to design the program block diagram of the algorithm to find the minimum odd number n that meets the conditions.

Algorithm analysis: because it involves the problem of class addition, the algorithm contains a loop structure until it is written to the type.

The algorithm steps of circular structure are as follows:

The first step is to make S = 0 and I = 1.

Step 2, calculate S=S+i, i=i+2.

The third step is to judge S> in 2008? If yes, outputting n-2 to end the algorithm; Otherwise, return to the second step.

Drawing steps: ① Draw a sequence structure diagram, namely the start-stop box and two processing boxes, and fill in the initial conditions of the cycle, as shown in Figure ① * * *; (2) Draw the circular structure diagram, and draw the circular body first.

That is, two processing blocks * * * one accumulate and one count * * *, and then the withdrawal cycle ends.

Stop conditions, that is, judging the box, judging S & gt2008? If so, output.

N-2, otherwise * * * will be circulated again before it flows to the circulating body, as shown in Figure ② * * *;

(3) Draw the output box to output n-2, and the start-stop box indicates the end of the algorithm.

Figure 3 * * *.

Finally, the block diagram of the algorithm is shown in Figure 2.

Comments: Circular structure must include sequence structure and conditional structure, so this question is typical and exemplary; When designing algorithms that need to be executed repeatedly, such as accumulation and class multiplication, we should use circular structure. At this time, we should pay close attention to the block diagram design of three important components: loop body, loop variable and loop termination condition.

Related symbols of flow chart

Data flow chart Data flow chart represents the data path to solve the problem. At the same time, the main stages of processing and various data media used are specified.

The data flow chart includes:

A data symbol indicating the existence of data, and these data symbols can also indicate the medium used by the data;

B. a processing symbol indicating the processing performed on the data, which may also indicate the machine functions used in the processing;

C. Streamline symbols, which represent the data flow between several processes and * * * or * * * data media;

D. read and write special symbols of data flow diagram.

There should be data symbols before and after processing symbols. The data flow chart begins and ends with the data symbol * * *, except for the special symbols specified in 9.4 * * *.

program flow chart

The program flow chart shows the sequence of operations in the program.

The program flow chart includes:

A. processing symbols indicating actual processing operations, including symbols for determining a path to be executed according to logical conditions;

B, a streamline symbol representing the control flow;

C. Special symbols for reading and writing program flow charts.

system flowchart

The system flow chart shows the operation control and data flow of the system.

The system flow chart includes:

A data symbol indicating the existence of data, and these data symbols can also indicate the medium used by the data;

B, defining a logical path to be executed and a processing symbol indicating an operation to be performed on the data;

C. Streamline symbols represent the data flow between each process and * * * or * * * data media;

D. Special symbols for reading and writing system flow charts.

Program network diagram

The program network diagram shows the activation path of the program and the interaction between the program and related data. In the system flow chart, the program may be located in

Appears in multiple control flows; But in the program network diagram, each program only appears once.

The plan network diagram includes:

A. data symbols indicating the existence of data;

B. processing symbols indicating operations to be performed on data;

C. Streamline symbols indicate the activation of each process and the flow direction between the process and the data;

D. Special symbols for reading and writing program network diagrams.

System resource map

The system resource diagram represents the configuration of data units and processing units suitable for solving a problem or a group of problems.

The system resource map includes:

A. data symbols representing input, output or storage devices;

B. Processing symbols representing processors * * *, such as central processing unit and channel * * *;

C, simplifying symbols representing data transmission between data equipment and processors, and controlling the transmission between processors;

D. Special symbols for reading and writing the system resource map.