<meta http-equiv="refresh" content="1; url=/nojavascript/"> Visual Tools for Problem Solving | CK-12 Foundation
Dismiss
Skip Navigation
You are reading an older version of this FlexBook® textbook: Engineering: An Introduction to Solving Engineering Problems with Matlab Go to the latest version.

Using an abstract visual representation while developing a program structure is often a useful technique. Several different visual representations have been developed; one of the most comprehensive is UML (http://www.uml.org). Two of the simplest are introduced in this section: flow charts and pseudo code. In both flow charts and pseudo code, elements of the problem solution are described using natural language statements that are visually arranged to show the structure of the program.

A flow chart represents elements of the solution to a problem as statements enclosed in boxes; the sequence in which use elements are performed is identified by arrows connecting the boxes. Figure 1 shows an example flow chart.

Pseudo code represents the elements of the solution to a problem as a sequence of statements.The statements are formatted to show the logical structure of the solution. Figure 2 shows an example of pseudo code.

The following example demonstrates the use of flow charts and pseudo code to develop the structure of a program that solves an engineering problem.

The ACME Manufacturing Company is planning to manufacture widgets (see http://en.wiktionary.org/wiki/widget for a definition of widget). There are two different manufacturing processes: one cost $10,000 to implement and can manufacture up to 1000 widgets, while the other cost $100,000 to implement and can manufacture up to one million widgets. In addition to the manufacturing cost, there is a fixed cost of $1 per widget (for packing and shipping each widget to the customer). Consider the problem of calculating the cost per unit to manufacture and ship a given number of widgets.

One way to solve the problem is to complete the following steps:

  • Get the number of widgets to be produced.
  • Determine the total manufacturing costs.
  • Determine the total fixed costs.
  • Determine the total cost.
  • Compute the cost per unit.

Figure 1 shows a flow chart that represents these steps. Figure 2 shows the pseudo code that represents these steps.

A flow chart for the widget production problem.

A flow chart for the widget production problem.

Get the number of widgets to be produced.
Determine the manufacturing costs.
Determine the total fixed costs.
Determine the total cost.
Compute the cost per unit.

Figure 2: Pseudo code for the widget production problem.

Having developed an initial solution, we can refine those elements whose implementation may not yet be fully defined. In this example, the manufacturing cost depend on the number of widgets to be made; if this number is less than or equal to 1000, the cost is $10,000, while if the number is greater than 1000, the cost is $100,000. We can represent this using the flow chart blocks in Figure 3. The diamond is a conditional; the branch of the flow chart that is actually executed depends on whether the conditional is true or false.

A flow chart for the manufacturing costs.

A flow chart for the manufacturing costs.

Putting this conditional into the complete flow chart gives the flow chart in Figure 4. The conditional is incorporated in the the pseudo code to give the pseudo code in Figure 5.

The complete flow chart for the problem.

The complete flow chart for the problem.

Get the number of widgets to be produced.
if number of widgets > 1000
manufacturing costs are $100,000
else
manufacturing costs are $10,000
Determine the total fixed costs.
Determine the total cost.
Compute the cost per unit.

Figure 5: Pseudo code for the widget production problem.

There are advantages and disadvantages for both flow charts and pseudo code. Advantages of using a flow chart include that it provides a strong visual representation of the program and that it is straightforward for novice programmers to use. The primary disadvantage of using a flow chart is that it is possible to create a flow chart that can only be implemented by "spaghetti code" (http://en.wikipedia.org/wiki/Spaghetti_code). Spaghetti code is considered extremely bad form for many reasons; in particular, it is hard to understand, debug and modify. The primary advantage of pseudo code is that its structure is clearly related to the available control structures in modern computer languages. Pseudo code has several disadvantages: it is not a very strong visual representation, and it is less straightforward for novice programmers.

Image Attributions

Files can only be attached to the latest version of None

Reviews

Please wait...
Please wait...
Image Detail
Sizes: Medium | Original
 
CK.ENG.ENG.SE.1.Engineering-Matlab.2.2
ShareThis Copy and Paste

Original text