<< Chapter < Page Chapter >> Page >
This module provides a brief introduction to the use of flow charts and pseudo code as aids in problem solving.

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 . Two of the simplest are introduced in this module: 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. 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. 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 . 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.

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

First flow chart

A flow chart for the widget production problem.

First pseudo code

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.
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 . The diamond is a conditional; the branch of the flow chart that is actually executed depends on whether the conditional is true or false.

Flow chart for manufacturing costs

A flow chart for the manufacturing costs.

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

Complete flow chart

The complete flow chart for the problem.

Complete pseudo code

Get the number of widgets to be produced. if number of widgets > 1000manufacturing costs are $100,000 elsemanufacturing costs are $10,000 Determine the total fixed costs.Determine the total cost. Compute the cost per unit.
Pseudo code for the widget production problem.
Got questions? Get instant answers now!

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" . 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.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Freshman engineering problem solving with matlab. OpenStax CNX. Apr 23, 2007 Download for free at http://cnx.org/content/col10325/1.18
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Freshman engineering problem solving with matlab' conversation and receive update notifications?

Ask