58
LESSON 25 FLOWCHARTING

Different Flowchart Design

Embed Size (px)

Citation preview

Page 1: Different Flowchart Design

LESSON 25

FLOWCHARTING

Page 2: Different Flowchart Design

25.1 INTRODUCTION

The flowchart is a means of visually presenting the flow of data through an information processing systems, the operations performed within the system and the sequence in which they are performed. In this lesson, we shall concern ourselves with the program flowchart, which describes what operations (and in what sequence) are required to solve a given problem. The program flowchart can be likened to the blueprint of a building. As we know a designer draws a blueprint before starting construction on a building. Similarly, a programmer prefers to draw a flowchart prior to writing a computer program. As in the case of the drawing of a blueprint, the flowchart is drawn according to defined rules and using standard flowchart symbols prescribed by the American National Standard Institute, Inc.

25.2 OBJECTIVES

At the end of this lesson, you will be able to understand:

the meaning of flowchart the basic parts of the flowchart such as flowchart symbols and the flow lines connecting

these symbols.

the advantages and limitations of flowchart

25.3 MEANING OF A FLOWCHART

A flowchart is a diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem. Flowcharts are generally drawn in the early stages of formulating computer solutions. Flowcharts facilitate communication between programmers and business people. These flowcharts play a vital role in the programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems. Once the flowchart is drawn, it becomes easy to write the program in any high level language. Often we see how flowcharts are helpful in explaining the program to others. Hence, it is correct to say that a flowchart is a must for the better documentation of a complex program.

25.4 GUIDELINES FOR DRAWING A FLOWCHART

Flowcharts are usually drawn using some standard symbols; however, some special symbols can also be developed when required. Some standard symbols, which are frequently required for flowcharting many computer programs are shown in Fig. 25.1

Start or end of the programComputational steps or processing function of a programInput or output operationDecision making and branchingConnector or joining of two parts of programMagnetic Tape Magnetic Disk

Page 3: Different Flowchart Design

Off-page connector Flow line Annotation

Display

 

Fig. 25.1 Flowchart Symbols

The following are some guidelines in flowcharting:

a. In drawing a proper flowchart, all necessary requirements should be listed out in logical order.

b. The flowchart should be clear, neat and easy to follow. There should not be any room for ambiguity in understanding the flowchart.

c. The usual direction of the flow of a procedure or system is from left to right or top to bottom.

Page 4: Different Flowchart Design

d. Only one flow line should come out from a process symbol.

  or       

e. Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.

             

f. Only one flow line is used in conjunction with terminal symbol.

                

g. Write within standard symbols briefly. As necessary, you can use the annotation symbol to describe data or computational steps more clearly.

h. If the flowchart becomes complex, it is better to use connector symbols to reduce the number of flow lines. Avoid the intersection of flow lines if you want to make it more effective and better way of communication.

i. Ensure that the flowchart has a logical start and finish.

j. It is useful to test the validity of the flowchart by passing through it with a simple test data.

 

25.5 ADVANTAGES OF USING FLOWCHARTS

The benefits of flowcharts are as follows:

Page 5: Different Flowchart Design

1. Communication: Flowcharts are better way of communicating the logic of a system to all concerned.

2. Effective analysis: With the help of flowchart, problem can be analysed in more effective way.

3. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.

4. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase.

5. Proper Debugging: The flowchart helps in debugging process.

6. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part

25.6 LIMITATIONS OF USING FLOWCHARTS

1. Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy.

2. Alterations and Modifications: If alterations are required the flowchart may require re-drawing completely.

3. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.

4. The essentials of what is done can easily be lost in the technical details of how it is done.

 

Top

IN-TEXT QUESTIONS 1

1. Fill in the blank.

i. A program flowchart indicates the_________ to be per formed and the __________ in which they occur.

ii. A program flowchart is generally read from _____________ to ________________

iii. Flowcharting symbols are connected together by means of ___________________

iv. A decision symbol may be used in determining the ____________ or ___________ of two data items.

Page 6: Different Flowchart Design

v. __________ are used to join remote portions of a flowchart

vi. ____________ connectors are used when a flowchart ends on one page and begins again on other page

vii. A ________ symbol in used at the beginning and end of a flowchart.

viii. The flowchart is one of the best ways of ________ a program..

ix. To construct a flowchart, one must adhere to prescribed symbols provided by the __________ .

x. The programmed uses a ____________ to aid him in drawing flowchart symbols.

 

Top

25.7 FEW EXAMPLES ON FLOWCHARTING

Now we shall present few examples on flowcharting for proper understanding of this technique. This will help in student in program development process at a later stage.

Example 1

Draw a flowchart to find the sum of first 50 natural numbers.

Answer: The required flowchart is given in Fig. 25.2.

Page 7: Different Flowchart Design

 

Fig. 25.2 Sum of first 50 natural numbers

Fig 2.2 Flowchart for computing the sum of first 50 natural numbers.

Example 2

Draw a flowchart to find the largest of three numbers A,B, and C.

Answer: The required flowchart is shown in Fig 25.3

Page 8: Different Flowchart Design

Fig 25.3 Flowchart for finding out the largest of three numbers

 

Example 3

Draw a flowchart for computing factorial N (N!)

Where N! = 1 ´ 2 ´ 3 ´ …… N .

The required flowchart has been shown in fig 25.4

Answer:

Page 9: Different Flowchart Design

 

Fig 25.4 Flowchart for computing factorial N

 

Top

IN-TEXT QUESTION 2

1. Define Flowcharting.

25.8 WHAT YOU HAVE LEARNT

In this lesson, we have discussed the advantages and limitation of flowcharting. We have also shown some examples of flowcharting. This will help the students in learning this technique easily.

Page 10: Different Flowchart Design

25.9 TERMINAL QUESTIONS

1. Draw a flowchart to read a number N and print all its divisors.2. Draw a flowchart for computing the sum of the digits of any given number

3. Draw a flowchart to find the sum of given N numbers.

4. Draw a flowchart to computer the sum of squares of integers from 1 to 50

5. Draw a flowchart to arrange the given data in an ascending order.

25.10 FEEDBACK TO IN-TEXT QUESTIONS

IN-TEXT QUESTIONS 1

1.  

i. Operations, sequence

ii. Top, down

iii. Flow line

iv. Equality, inequality

v. connectors

vi. Off -page

vii. Terminal

viii. documenting

ix. ANSI (American National Standards Institute)

x. Flowcharting template

flowchart

Page 11: Different Flowchart Design

traditional method of representing in schematic form the flow of data in a system. The flowchart shows the points of input and output, the logic or sequence of the various processing steps in the system, and the relationship of one element of the system to the other parts of the system or to other information systems.

Dictionary of Computer and Internet Terms flowchart

a chart consisting of symbols and words that completely describe an algorithm (i.e., how to solve a problem). Each step in the flowchart is followed by an arrow that indicates which step to do next.

The flowchart in Figure 108 shows how to calculate the cube root of a number a using Newton's method, where x is the guess for the cube root of a, and d indicates how accurate the result must be. The procedure will follow around the loop until |x3 - a| < ?.

"Start" and "stop" statements are written with ovals, action statements are written with squares, and decision statements are written in diamonds. A decision statement asks a yes-or-no question. If the answer is yes, the path labeled "yes" is followed; otherwise, the other path is followed.

Page 12: Different Flowchart Design

Writing a flowchart often helps to solve a complex programming problem, although flowcharts are seldom used now that structured programming has become popular.A flowchart is often much bulkier than the program it describes.

See also structured programming Dictionary of Business Terms flowchart

diagram consisting of symbols and words that completely describe an algorithm, that is, how to solve a problem. Each step in the flowchart is followed by an arrow that indicates which step to do next. A flowchart can also track a procedure, such as the steps involved in manufacturing a product.

Page 13: Different Flowchart Design

Dictionary of Marketing Terms flowchart

diagrammatic representation of a system or process utilizing various symbols connected by arrows showing the step-by-step sequence. Flowcharts are universally used in the design of computer systems and programs and may also be used to describe manual processes. The following is a very simplified diagram of the conversion of hard copy information to magnetic tape . A more sophisticated flowchart would describe the "process" with a series of symbols that fully represent every step in the process.

Page 14: Different Flowchart Design

Related Terms:structured programming

a programming technique that emphasizes clear logic, modularity, and avoidance of GO TO statements (which are intrinsically error-prone).

One of the most important barriers to the development of better computer software is the limited ability of human beings to understand the programs that they write. Structured programming is a style of programming designed to make programs more comprehensible and programming errors less frequent. Because it is more a popular movement than a precise theory, structured programming can be defined in several ways, but it usually includes the following;

1. Block structure. The statements in the program must be organized into functional groups. For example, of the following two Pascal program fragments, the first is structured, while the second is not:Note that it is much easier to tell what the first example does.

2. Avoidance of jumps ("GO-TO-less programming"). It can be proved mathematically that, if a language has structures equivalent to the (block-structured) IF-THEN and WHILE statements in Pascal, it does not need a GO TO statement. Moreover, GO TO statements are often involved in programming errors; the programmer becomes confused as to the exact conditions under which a particular group of statements will execute.

Advocates of structured programming allow GO TO statements only under very restricted circumstances (e.g., to deal with error conditions that completely break out of the logic of a program) or not at all.

3. Modularity. lf a sequence of statements continues uninterrupted for more than about 50 lines, human beings have a hard time understanding it because there is too much information for them to keep track of. As an alternative, programs should be broken up into subroutines, even if some of the subroutines are called only once. Then the main program will read like an outline, and the programmer will never need to understand more than about one page of code at a time. (The programmer must know what the subroutines do, but not how they do it.) This principle is sometimes called information hiding-irrelevant information should be kept out of the programmer's way. Structured programming was first advocated by E.W. Dijkstra in the early 1970s.

Page 15: Different Flowchart Design

Flowcode 4 Overview Overview Buy License Supported Devices Specification

 

FlowcodePublished by Matrix Multimedia, Flowcode is a flow chart programming language. This makes flowcode an excellent introduction into programming PIC microcontrollers.

Page 16: Different Flowchart Design

Behind the scenes the flow chart is turned into C-code which is then compiled by SourceBoost Technologies BoostC compiler.

The great advantage of Flowcode is that it allows those with little experience to create complex electronic systems in minutes.

 

Benefits Save time and money Flowcode facilitates the rapid design of electronic systems based

on microcontrollers. Easy to use interface Simply drag and drop charts on screen to create a electronic system

without writing traditional code line by line.

Fast & flexible Flowcode has a host of high level component subroutines which means rapid system development. The flowchart programming method allows users of all abilities to develop microcontroller programs.

Error free results Flowcode works. What you design and simulate on screen is the result you get when you download to your microcontroller.

Open architecture Flowcode allows you to view commented C and ASM code for all programs created. Access circuit diagram equivalents to the system you design through our data sheets and support material.

Fully supported Flowcode is supported by a wide range of materials for learning about, and developing, electronic systems.

Three steps to a working program

Step1 Design

Flowcode contains standard flow chart icons and electronic components that allow you to create a virtual electronic system on screen. Use the drag and drop interface to create a program and click on each icon and component to set the actions and properties you need. The range of components is large and includes simple switches and LEDs, communication bus interfaces like I2C and SPI, and more advanced components such as Bluetooth and internet servers.

Easy to use interface Allows complex systems to be developed and managed quickly

Supports PIC12, PIC16 and PIC18 Flash PICmicro microcontrollers

Step2 Simulate

Page 17: Different Flowchart Design

Once your system is designed you can use Flowcode to simulate it in action. Menu controls allow you to step through each icon in the program and see the effects on the on-screen components, and on the PICmicro microcontroller itself. Test the system’s functionality by clicking on switches or altering sensor values, and see how your program manages the changes in the electronic system.

Simulation aids understanding Debug before download

Shorten the design cycle

Step3 Download

When you are satisfied with your design click one button to send the program to your PICmicro microcontroller device. Flowcode produces standard Hex code for PICmicro microcontollers and is compatible with most programmers. Flowcode is directly compatible with the E-blocks range of modular electronics modules.

Compiles to C then ASM then Hex Link in your own C or ASM files

Immediately download to your PICmicro program

 

Page 18: Different Flowchart Design

Flowcode Development Environment

Appendix A

Programming Flowchart I

(through serial communication subroutine)

 

 

 

Page 19: Different Flowchart Design
Page 20: Different Flowchart Design

 

Appendix B

Programming Flowchart II

(after serial communication subroutine)

 

 

 

Page 21: Different Flowchart Design
Page 22: Different Flowchart Design

Figure 1: Development Kit Instructions [2]

System Description Techniques

 

Page 23: Different Flowchart Design

30.1 INTRODUCTION

Graphical representation of any process is always better and more meaningful than its representation in words. Moreover, it is very difficult to arrange and organise the large amount of data into meaningful interpretation of the whole. System Analysis and Design makes use of the various tools for representing and facilitating comprehension of the complex processes and procedure involved. In this lesson, we present some details about Flowcharts, data flow diagram (DFD), Decision Tables and Decision Trees.

 

30.2 OBJECTIVES

After going through this lesson you should be able to

Draw flowchart Represent any physical system through DFD

Prepare decision table

Display decision tree

30.3 FLOWCHARTS

The pictorial representation of the programs or the algorithm is known as flowcharts. It is nothing but a diagrammatic representation of the various steps involved in designing a system. Some of the boxes which are used in flowcharts are:

A flowchart consists of a set of ‘flowchart symbols’ connected by arrows. Each symbol contains information about what must be done at that point & the arrow shows the ‘flow of execution’ of the algorithm i.e. they show the order in which the instructions must be executed. The purpose of using flowcharts is to graphically present the logical flow of data in the system and defining major phases of processing along with the various media to be used.

Page 24: Different Flowchart Design

Flowcharts are of three types:

System flowcharts Run flowcharts

Program flowcharts

 

(a) System Flowcharts

System flowchart describes the data flow for a data processing system. It provides a logical diagram of how the system operates. It represents the flow of documents, the operations performed in data processing system. It also reflects the relationship between inputs, processing and outputs. Following are the features of system flowcharts:

the sources from which data is generated and device used for this purpose various processing steps involved

the intermediate and final output prepared and the devices used for their storage

Figure 30.1 is a sample of system flowchart for the following algorithm:

1. Prompt the user for the centigrade temperature.2. Store the value in C

3. Set F to 32+(9 C/5)

4. Print the value of C , F

5. Stop

Page 25: Different Flowchart Design

Figure: 30.1 System Flowchart

 

(b) Run flowcharts

Run flowcharts are used to represent the logical relationship of computer routines along with inputs, master files, transaction files and outputs. Figure30. 2 illustrates a run flowchart.

Page 26: Different Flowchart Design

Figure: 30.2 Run Flowchart

 

(c) Program flowcharts

A program flowchart represents, in detail, the various steps to be performed within the system for transforming the input into output. The various steps are logical/ arithmetic operations, algorithms etc. It serves as the basis for discussions and communication between the system analysts and the programmers. Program flowcharts are quite helpful to programmers in organising their programming efforts. These flowcharts constitute an important component of documentation for an application.

Figure 30.3 represents a program flowchart for finding the sum of first five natural numbers ( i.e. 1,2,3,4,5).

Page 27: Different Flowchart Design

Fig 30.3 Program Flowchart

(d) Data flow diagram

Data flow diagrams are the most commonly used way of documenting the process of current & required systems. As their name suggests they are a pictorial way of showing the flow of data into, around & out of a system.

(e) Defining DFD

Graphical representation of a system’s data and how the processes transform the data is known as Data Flow Diagram (or DFD). Unlike, flowcharts, DFDs do not give detailed descriptions of modules but graphically describe a system’s data and how the data interact with the system.

(f) Components of DFD

DFDs are constructed using four major components

external entries data stores

processes and

data flows

Page 28: Different Flowchart Design

(i) External Entities

External entities represent the source of data as input to the system. They are also the destination of system data. External entities can be called data stores out side the system. These are represented by squares.

(ii) Data Stores

Data stores represent stores of data within the system. Examples, computer files or databases. An open-ended box represents a data/store – data at rest or a temporary repository of data.

(iii) Process

Process represents activities in which data is manipulated by being stored or retrieved or transferred in some way. In other words we can say that process transforms the input data into output data. Circles stand for a process that converts data into information.

(iv) Data Flows

Data flows represents the movement of data from one component to the other. An arrow identifies data flow – data in motion. It is a pipeline through which information flows... Data flows are generally shown as one-way only. Data Flows between external entities are shown as dotted lines.

 

(g) Physical & Logical DFD

Consider the figure30.4. It is clear from the figure that orders are placed, orders are received, the location of ordered parts is determined and delivery notes are dispatched along with the order.

Fig 30.4

It does not however tell us how these things are done or who does them. Are they done by computers or manually and if manually who does them ? A logical DFD of any information system is one that models what occurs without showing how it occurs.

A physical DFD shows, how the various functions are performed? Who does them? Consider the following figure:

Page 29: Different Flowchart Design

Fig 30.5

The figure 30.5 is opposite, it shows the actual devices that perform the functions. Thus there is an "order processing clerk", an "entry into computer file" process and a "run locate program" process to locate the parts ordered. DFD(s) that shows how things happen, or the physical components are called physical DFD(s).

Typical processes that appear in physical DFDs are methods of data entry, specific data transfer or processing methods.

(h) Difference between flowcharts & DFD

The program flowchart describes boxes that describe computations, decisions, interactions & loops. It is an important to keep in mind that data flow diagrams are not program flowcharts and should not include control elements . A good DFD should

have no data flows that split up into a number of other data flows have no crossing lines

not include flowchart loops of control elements

not include data flows that act as signals to activate processes.

 

30.4 DECISION TABLES AND DECISION TREES

Decision tables and trees were developed long before the widespread use of computers. They not only isolate many conditions and possible actions but they help ensure that nothing has been overlooked.

(a) Decision Tables

Page 30: Different Flowchart Design

The decision table is a chart with four sections listing all the logical conditions and actions. In addition the top section allows space for title, date, author, system and comment as shown in the fig.30.6

Five sections of a decision table:

TITLE : Author :Comments :

DATE :System :

Condition Stub Condition Entry

Action Stub Action Entry

Figure 30.6 Decision Table

The condition stub contains a list of all the necessary tests in a decision table. In the lower left-hand corner of the decision table we find the action stub where one may note all the processes desired in a given module. Thus Action Stub contains a list of all the processes involved in a decision table.

The upper right corner provides the space for the condition entry - all possible permutations of yes and no responses related to the condition stub. The yes and no possibilities are arranged as a vertical column called rules. Rules are numbered 1,2,3 and so on. We can determine the rules in a decision table by the formula:

Number of rules = 2^N = 2N where N represents the number of condition and ^ means exponentiate. Thus a decision table with four conditions has 16 (24 = 2 x 2 x 2 x 2 = 16) rules one with six conditions has 64 rules and eight conditions yield 256 rules.

The Condition entry contains a list of all the yes/no permutations in a decision table. The lower right corner holds the action entry. X’s or dots indicate whether an action should occur as a consequence of the yes/no entries under condition entry. X’s indicate action; dots indicate no action.

Thus Action entry indicates via dot or X whether something should happen in a decision table. Let us consider the following example of book order illustrated by figure 30.7

If order is from book store

And if order is for 6 copies

Then discount is 25%

Else (if order is for less then 6 copies)

Page 31: Different Flowchart Design

No discount is allowed

Else (if order is from libraries)

If order is for 50 copies or more

Then discount is 15%

Else if order is for 20 to 49 copies

Then discount is 10%

Else if order is for 6 to 19 copies

Then discount is 5%

Else (order is for less then 6 copies)

No discount is allowed

A decision table for the above process is illustrated below

Figure 30.7: Decision Table

Page 32: Different Flowchart Design

(b) Decision Tree

The decision tree defines the conditions as a sequence of left to right tests. A decision tree helps to show the paths that are possible in a design following an action or decision by the user. Figure 30.8 illustrates the concept of decision tree.

Figure 30.8: Decision Tree

Decision tree turns a decision table into a diagram. This tool is read from left to right, decision results in a fork, and all branches end with an outcome. Figure 6 illustrates the decision tree for the book order decision table we saw earlier.

Figure 30.9: Decision Tree for Book Order

 

Top

30.5 What You Have Learnt

Various specification tools and techniques of system analysis and designing were discussed in detailed. The various tools such as flowcharts, data flow diagrams, decision tables & decision trees were explained. These tools and techniques are used when the system under study involves the development of computer based information system.

30.6 Terminal Questions

1. What is flow chart ?

Page 33: Different Flowchart Design

2. Explain different types of flow charts.

3. Define DFD. Explain different components of DFD.

4. Explain decision table and decision tree.

Introduction to Fundamental Programming Concepts

Robert Mannell

Before we examine the process of planning a speech synthesis or text-to-speech project, we will first examine some basic programming concepts.

There are five steps in program development:-

Defining the problem Planning the solution

Coding the program

Testing the program

Documenting the program

The first step in this process is not a trivial step, particularly when you are writing a program for someone else, or when you are getting someone to write a program for you. The types of input and output, and the intervening procedures which will be carried out on the data must be well defined. If more than one party is involved than they must all be sure that they understand the problem in the same way. The problem must be defined in detail.

The planning stage is largely the problem of the programmer, although from time to time it will be necessary to check back with the person who commissioned the program to ensure that the program (as it evolves into greater detail) still matches the user's requirements. There are a number of ways of developing a program. One method is a graphical technique called flowcharting which will be examined briefly here. Another method is the definition of the problem in pseudocode. Pseudocode is a formal language which resembles natural English but which is sufficiently constrained and formalised to allow a precise statement of the program's structure.

Page 34: Different Flowchart Design

The coding stage is the translation of the program from flowcharts or pseudocode to the programming language of choice.

The testing stage is always necessary. What you are looking for are errors (bugs) in your program and you will nearly always find some. The most common way to test for errors (often called debugging or looking for and removing bugs) is to pass the program through a translator program. The translator program expects the program to follow very rigid syntactic rules. If this is not so the translator will send you an error message (ie. it will tell you, by displaying a message on the screen, that you have made a syntax error). For many languages, the translator examines the entire program at one time and translates the program into a code that the machine can understand (machine code). Such a translator program is called a compiler and most programmers can often be heard talking about "compiling" their programs. The process of compiling a program results in a file called an executable. When you run the program, you use this executable file rather than directly using the source code. In scripting languages such as Perl and Tcl/Tk and languages such as BASIC, source code is translated line by line when you execute the code and any syntax errors are reported at that time. Such a run-time translator program is called an interpreter program.

Even if you get the syntax right, however, there is no guarantee that your program will do what you want it to do. The logic (or semantics) of the program might be wrong just as a syntactically correct English sentence might be meaningless or may mean something that was not intended.

For example:-

The sentence, "Colourless green ideas sleep furiously", is syntactically well-formed but is quite meaningless.

The sentence, "The boy hit the girl", is both syntactically well-formed and is also meaningful, but may still be in error if the intended message was "The girl hit the boy."

The final stage in program development is the documentation stage. This stage is essential because you may forget the details of your program after a few months and may be required to modify it for some reason (eg. a well hidden bug may have been found). How can you alter the program if you don't remember how it works? Even more importantly, you may not be the person called upon to alter the program. How can someone else be expected to understand your program if you have not carefully documented it?

It is good programming practice to document your software as you plan and write it. A number of tools are available (eg. UML and Doxygen) which assist programmers with this process.

Conditions

A condition is any logical or mathematical statement (or expression). Such a statement can be either true or false.

The following are examples of conditions:-

Page 35: Different Flowchart Design

STATEMENT/EXPRESSION TRUE/FALSE

1. The sky is green with red spots. FALSE

2. Aristotle was a man. TRUE

3. 1 + 2 = 3 TRUE

4. 1 + 2 = 4 FALSE

5. 4 > 3 TRUE

6. 4 < 3 FALSE

7. A = 3 unknown

8. A = B unknown

9. A > B unknown

Of the above, we only know if a statement is correct if we know the value of each item. We know, for example that the sky is blue (on a cloudless day), therefore the first statement is false. We know that Aristotle was a man, therefore the second statement is true. The numbers 1, 2, 3, and 4 have fixed values and therefore we can readily evaluate expressions 3 to 6 as true or false. If an item in an expression has a fixed value (eg. a number or sky=blue, Aristotle=man) then such an item is referred to as a constant.

If an item does not have a fixed value (ie. if its value can be changed) such an item is called a variable. When algebraic variables (such as "A" and "B" in expressions 7 to 9) occur in a statement they cause that statement's truth to be unknown unless the values of the variables have been previously defined. Statements 7 to 9 need to be qualified in the following ways before the conditions can be evaluated. In other words the variables need to be (temporarily) allocated a value.

7. LET A = 3, A = 3 ? TRUE

LET A = 5, A = 3 ? FALSE

8. LET A = 10, LET B = -3.6, A = B ? FALSE

LET A = 8, LET B = 8, A = B ? TRUE

9. LET A = 99.99, LET B = -5000, A > B ? TRUE

Variables

In most programming languages there are at least two types of variables, numerical variables and alphanumeric (or string) variables. String variables have text values rather than number values (eg. B$ = 'FRED')

Flowcharts

Page 36: Different Flowchart Design

Flowcharts are graphical methods of outlining program structure and generally utilise a set of standard symbols known as the ANSI (American National Standards Institute) symbols. The ones that we will mostly use are shown in figure 1.

Figure 1: Some standard flowcharting symbols.

Structured Programming

One of the most important features of structured programming is that all program structures have only one entry point and one exit point.

There are three main types of control structures

1. Sequence (see figure 2)2. Selection (IF-THEN), (IF-THEN-ELSE), see figure 3; IF-THEN-ELSEIF-THEN-ELSE,

see figure 4)

3. Iteration (DO-WHILE, see figure 5; DO-UNTIL, see figure 6)

A sequence of instructions in a sequence structure must all be carried out.

In a selection structure certain instructions will only be carried out IF a certain condition is found to be true.

In an iteration structure certain instructions will be repeatedly carried out until a condition is no longer true (DO-WHILE) or alternatively until a condition is no longer false (DO-UNTIL). Such structures consist of a loop which takes the program back to the top of the instructions to be repeated.

Page 37: Different Flowchart Design

Figure 2: An example of a sequence control structure.

Figure 3: An example of a selection (IF-THEN-ESLE) control structure. This flowchart means:- IF "Condition" is true THEN perform "Procedure 2", ELSE perform "Procedure 3".

Page 38: Different Flowchart Design

Figure 4: An example of a selection (IF-THEN-ELSEIF-THEN-ELSE) control structure. This flowchart means:- IF "Condition 1" is true THEN perform "Procedure 2", ELSE IF "Condition 2" is true THEN perform "Procedure 3" ELSE perform "Procedure 4".

Page 39: Different Flowchart Design

Figure 5: An example of an iteration (DO-WHILE) control structure. Note that the loop condition (in this case the question "is i < 10?") is tested before proceding with the rest of the procedures in the loop and that the loop control variable ("i") is incremented at the end of the loop. If the loop condition is true then the loop is executed. The loop only terminates when the loop condition is false. If the loop condition is false upon entry to the loop then the loop isn't executed at all.

Page 40: Different Flowchart Design

Figure 6: An example of an iteration (DO-UNTIL) control structure. Note that the loop condition (in this case the question "is i > 10?") is tested at the end of the loop. The loop control variable (in this case "i") can be updated anywhere in the loop and here is incremented just before the loop condition is tested. If the loop condition is true then the loop is terminated. The loop only repeats when the loop condition is false. Even if the loop condition is true upon entry to the loop the loop will be executed at least once.

Pseudocode

Page 41: Different Flowchart Design

An example of pseudocode is given here as a brief illustration of its structure. This example is a pseudocode version of the IF-THEN-ELSE flowchart in figure 4. Some developers prefer to use pseudocode rather than flowcharts.

IF condition is true THENtrue statement 1true statement 2...true statement n

ELSEfalse statement 1false statement 2...false statement n

ENDIF

Unified Modeling Language (UML)

"The UML is a modelling language for specifying, visualizing, constructing, and documenting the artifacts of a system-intensive process."

Sinan Si Alhir, UML in a Nutshell: A Desktop Quick Reference, O'Reilly, 1998.

UML has become very popular in recent years as a standard way of planning, constructing and documenting software projects. It has the advantage of facilitating these processes using graphical visualisation tools. A number of popular UML-based tools (eg. Visual Rose, and Microsoft's Visio) are also able to generate from a visualised project structure the basic classes that the programmer will need to elaborate in order to complete the project.

UML uses diagrams, some of which resemble traditional flowcharts, to visualise the way objects and people will interact when the project is completed. UML is an object-oriented tool that is particularly suited to the design of projects that use object-oriented languages such as C++ or Java.

Traditional flowcharts and pseudocode, on the other hand, are suited to procedural approaches to programming. However, once the classes for an object-oriented project have been designed, class member functions can still be profitably designed using flowcharts.

Some speech technology companies utilise UML during the development and documentation of their products. Poseidon for UML is being used in our research centre for certain speech and hearing software projects.

The Object-oriented Approach to Programming

Page 42: Different Flowchart Design

Traditional programming techniques concentrated on the structural and dynamic characteristics of a problem during project development. Such approaches can focus either on the behaviour (process or function driven) or on the data (data-driven) aspects of a problem.

Object-oriented programming techniques treat both the data-like and process-like elements of a problem as parts of a complete unit. Central to the object-oriented paradigm is the concept of the "class". A class defines both the structure of the data and the processes that act upon that data for a logical component of a project. A class contains both member data variables and member functions. The functions are specialised to operate only on variables that are members of their own class.

A class is a set functions and related data structures found in programming code, whilst an object is an instance of that class that is being used to interact with actual data.

Typical non-object-oriented procedural languages include Fortran, Cobol, and C (but note that recently there has been an effort to develop object-oriented Fortran as part of the Fortran 2000 and Fortran 2003 standards).

Typical object-oriented languages are C++ (which evolved from C) and Java.

C++ is probably the most commonly used language in the development of commercial speech technology.

Python is also an object oriented language. Python can be embedded into a project (which is often written in another language, such as C++) so that end users can write Python scripts that interact with the built in classes of that host project. Python is a popular language for various language processing tasks and is the scripting language of choice for the Natural Language Toolkit (NLTK).

Page 43: Different Flowchart Design

The Repetition Control Structure (a.k.a. Looping)

Underlined items below link to other web pages when selected. To return to this page, tap your Backspace key. Items in [brackets] will open a new browser window. Switch between this one and it using the Alt+Tab keys. Close the new window when done viewing it by clicking on the button in the upper right-hand corner.

This document introduces fundamental concepts related to the design of repetitious processes. Readers of this document may benefit from a review of Flowcharting Symbols and Logical Control Structures. Readers who have difficulty rendering flowcharts are provided with links to alternative text-based outlines prior to each flowchart below. For specific examples of loop algorithms and C Language code, view the web pages entitled Example of a Counting Loop (Repetition Structure) and Analysis of an accumulation using the repetition structure.

Repetition is the act of repeating one or more steps in a process. It involves a branching backwards away from the normal sequence of steps towards an earlier step. The branching decision is based on a condition (relationship between the values of known data) at the time that the branching test is performed. The condition is normally based on the value of a single variable known as the control variable. The step or steps to be repeated are referred to as the loop body. Each execution of those steps is referred to as a pass or iteration. The step at which the body starts is known as the loop entrance and the step at which the test to branch back fails (causing repetition to cease) is known as the loop exit. The illustration below shows two variations of control structure commonly used by analysts when designing repetitive processes. Readers who have difficulty rendering flowcharts can read the alternative [text-based outlines] for these examples instead.

Page 44: Different Flowchart Design

The major issues involved in loop design are: structure, method of control, and boundary conditions. These will be discussed in detail in the following paragraphs, but are listed briefly below to introduce them.

Structure - involving the order of the steps to be repeated with repect to decision making step (shown in a diamond-shaped symbol in the flowcharts above) that causes the repetition. Practitioners of structured design recognize two basic repetition structures: leading decision and trailing decision. A third structure involving middle decision can be used by analysts, but is usually discarded in favor of one of the other two forms.

Method of Control - relating to the source of the control variable (data upon which the branching condition is based).

o Counting control is based on testing the value of a control variable known as the counter that was incrementally increased or decreased until a specific value was met or exceeded. Because the value of a counter is controlled entirely by the programmer, this method of control is often called internal control.

o Sentinel control is based on testing the value of a control variable that was read from the keyboard or other input device until a specific value was met or exceeded. The value that is tested to control the loop is called the sentinel value. Because the value of the control variable in this method of control is obtained from reading input, this method is often called external control.

Boundary Conditions - which relate to the values of data involved in the loop at both its entrance and its exit.

Loop Design Issues - in Detail

Page 45: Different Flowchart Design

STRUCTURAL ISSUES

When programmers want to repeat a step within a program a known number of times, some additional steps will be required to implement the repetition. A test must be added to determine if a repetition should take place or end. Other additional steps might also be required if the repetition is dependent on controlling a counter of events (passes). The step at which the loop starts is called its entrance and the last step performed before completion is called its exit. Programmers have learned over the years that the conditional test that controls the exit from a loop should be placed either immediately following the entrance to the loop or following all steps in its body, but never in the middle of the body. Loops that have their tests in the middle are often error prone and difficult to debug. Loops with their tests at the entrance are said to use a leading decision and those with their tests after their entire body use a trailing decision. Programming languages offer a variety of statements to implement the two repetitive control structures. Beware that many of the keywords used to do this are not handled in the same manner by each language. Some of the more popular keywords are: while, for, do, and until. Some times these are used in combination. Students are cautioned to avoid using such keywords to describe the structure of a loop because each language uses these words differently. Authors of textbooks about the C Language often refer to leading decision loops as "while-do" loops, and refer to trailin decision loops as "do-while" loops. Others call trailing decision loops "repeat-until" loops. Do not fall into this bad habit of using language keywords to discuss logical control structure. Stick with the terms "leading" and "trailing" decision. They are not language-dependent.

Many loops can be written using either the leading or trailing decision structure without any detrimental effect on the results. But (for example) if I was writing a loop to repeatedly display lines on a report that were based on complex calculations, I would probably chose to use the trailing decision structure. The trailing position of the test would guarantee that I would see at least one line of output even if the conditions forced an exit after the first pass. If my program's calculations were producing flawed results and I chose (unwisely) to use a leading decision structure, the test might force an exit from the loop before I (or the user) had a chance to see any of the values causing the trouble. In a different program involving erasure of data or activation of dangerous equipment, I might want to guarantee that a test was always performed prior to any action being done in the body of a loop (because its action was hazardous). In that case, I would chose to use the leading decision structure.

Novice programmers often develop loops that perform their test in the middle of the body as shown in the illustration below. Readers who have difficulty rendering flowcharts can read the alternative [text-based outline] instead. This approach appears to be quite logical and is often more efficient that either the leading or trailing decision approaches. And yet, many modern programming languages have no command to implement this approach because it has been determined to be more likely to contain flaws and difficult to debug. Any loop design that tests in the middle can be redesigned to test at the entrance or exit, but will usually require the addition of some extra steps (overhead) to accomplish the its objective. The benefit is that almost all programming languages have commands to implement both the leading and trailing decision structures.

Page 46: Different Flowchart Design

CONTROL ISSUES

The choice of control method is dictated by whether the decision to perform repetitious steps is supposed to be controlled by the user or by the programmer. If the decision to repeat is to be based on a value entered by the user, then the control method is sentinel (external) control. If the decision to repeat is to be based on a value established and controlled solely by the programmer without any input by the user, then the control method is counting (internal) control. In some loops, the decision condition is not as simple. It is based on more than one factor; one user-defined, another programmer-defined. Situations like that use hybrid (combined) control and involve more complex conditional expressions.

It is important to draw a distinction between loops that involve counting as part of their purpose and other loops that use counting as their method of control. Just because a loop involves counting, does not guarantee that its control method is based on the value of the counter. So not all loops that count are "counting controlled" loops. Sentinel loops might also do some counting.

Consider the following illustration that shows two different structural approaches that could be used in designing a loop that requires the counting method of control employing a counter variable labeled C. The objective of the loop is to display the word "Hello" five times on separate lines. In this example, the counter C has nothing to do with the action to be repeated (display of the word) except to control how many times the action will take place. Some loops do contain bodies that involve the counter. This would be the case in this example if the object of the body was to display the value of the counter instead of the word "Hello", in which case the output would be a column of numerals (1 through 5). (For an example of such a loop see the web page Example of a Counting Loop (Repetition Structure).

The flowchart below on the left shows the original process using the trailing decision structure. The flowchart below on the right shows the original process using the leading decision structure. Readers who have difficulty rendering flowcharts can read the alternative [text-based outlines] for these examples instead. As stated in the section above about structure, the choice of one

Page 47: Different Flowchart Design

looping structure over another often has no effect on the ability of the structure to accomplish its objectives. Both of the structures below will work equally well to accomplish the task.

The comments included in the flowcharts above relate to the fact that all counting controlled loops contain (at least) four basic elements. These are:

Initialization - prior to the loop entry, a first value of the control variable is set Body - containing the step (or steps) to be repeated

Increment/Decrement - where the control variable is increased (or decreased)

Test - where the control variable is tested to determine whether control should pass or exit

These elements do not always occur in the order shown above, but they are always present (in counting controlled loops).

The C source code for the trailing decision approach shown in the flowchart above on the left would be

#include <stdio.h> /* Standard Input/Output header file */

int C; /* Counter */

int main (void){ C = 1; /* Initialize counter to start at one */ do

Page 48: Different Flowchart Design

{ /* Start a pass through the loop */ printf ("Hello\n"); /* This step is the "body" of the loop */ C = C + 1; /* Increment C by one */ } /* End the pass through the loop */ while (C<=5); /* Test for repetition/exit AFTER the body */ return (0); /* Return zero error code to parent process */}

Note the need for the braces { } surrounding the body and increment. The do statement must contain the actions to be repeated. It (like most branching oriented statements in C) can perform only one statement. So if we need to have more than one performed, they need to be enclosed in braces to have C treat them as a compound statement. The while statement performs the test of the parenthesized condition. If it is true control branches back to the do statement. If not, or not, control continues in sequence to the next statement following the while statement.

The C source code for the leading decision approach shown in the flowchart above on the right would be

#include <stdio.h> /* Standard Input/Output header file */

int C; /* Counter */

int main (void){ C = 1; /* Initialize counter to start at one */ while (C<=5) /* Test for repetition/exit BEFORE the body */ { /* Start a pass through the loop */ printf ("Hello\n"); /* This step is the "body" of the loop */ C = C + 1; /* Increment C by one */ } /* End the pass through the loop */ return (0); /* Return zero error code to parent process */}

We also need braces { } surrounding the body and increment here. The while statement performs the test and if the parenthesized condition is true, executes the single (or braced) statement(s) beyond the while statement. Then control branches back to the while statement to perform the test again. If the condition is false, control branches ahead (in the code) to the next statement following the single (or braced) statement(s) beyond the while statement (in this example: return (0)).

BOUNDARY CONDITION ISSUES

In the loops above, the value of the control variable is not be directly involved in the steps being repeated. The counter must step through five values, but the actual values are not intimately involved in the process being repeated. In such cases, any values for the counter would be acceptable as long as the desired quantity of repetitious passes occurs. The counter could run from 1 to 5, 11 to 15, or down from 5 to 1, and produce the same five events. The counter could also step using increments other than 1. For example, the following automatic looping statement (although a bit odd) would accomplish the goal of the "Hello" loop above:

Page 49: Different Flowchart Design

float N; for ( N=1.1; N<=1.5; N=N+0.1 ) printf ("Hello\n");

(If you are not familiar with automatic "for loops", look in your textbook in chapter 5.) Often when designing loops, the exit value of the control variable is important to us. For example, consider the following loop:

int C; C = 1; while (C<=5) { printf ("Hello\n"); C=C+1; }

In the loop above, C would have an exit value of 6, because it had to exceed 5 for the test to produce a false result and allow an exit from the loop. However, the last value that user would see would be 5. The loop design could be altered to guarantee that the last value displayed was the exit value. One such design would be:

int C; C = 0; while (C<5) { N=N+1; printf ("Hello\n"); }

Note that:

1. the initial value was altered2. the test condition had to be slightly altered, and

3. the order of the steps in the braced pass changed

Designers should always consider the entrance and exit values of all variables that are to be effected by a loop

current definitions of data sizes in programming:

kilobyte = 2^10 bytes = 1024 bytesmegabyte = 2^20 bytes = 1048576 bytesgigabyte = 2^30 bytes = 1073741824 bytesterabyte = 2^40 bytes = 1099511627776 bytespetabyte = 2^50 bytes = 1125899906842624 bytesexabyte = 2^60 bytes = 1152921504606846976 byteszettabyte = 2^70 bytes = 1180591620717411303424 bytesyottabyte = 2^80 bytes = 1208925819614629174706176 bytes