Vous êtes sur la page 1sur 3

ECEE2: Visual Basic 6.

0 Lecture 3: Algorithm and Flowcharting Algorithm A list of instructions for carrying out some process step by step. It is an English-like way of writing and expressing a solution to a problem. It helps us to construct the actual program easily and clearly. Flowcharts It is diagram representing the logical sequence in which a combination of steps or operations is to be performed. - It consists of labeled geometrical symbols that are interconnected to provide a pictorial representation of a data processing procedure. - It is a visual representation of an algorithm - Widely used graphic method for describing computer operations. Two types of Flowcharts 1. System Flowchart Provides an overview of the entire operation without itemizing all the specific input, processing, and output steps that will actually be performed - Similar to the block diagram of the system. 2. Macro Flowchart/ Program Flowchart - Depicts the main segments of a complete computer program - Detailed flowcharts that illustrate processing steps within a program module. Flowcharting Guidelines 1. Always use the American National Standard Institute (ANSI) standard symbols; 2. Construct your flowcharts to read from top to bottom and left to right; 3. Do not crisscross flow lines (use labeled connectors and arrowheads to indicate direction of flow); 4. Make messages and labels in flowchart symbol and description. 5. Strive for neatness, clarity, and simplicity. Flowcharting Advantages 1. 2. 3. 4. 5. Supply graphic representations; Provides standardization; It can have application to both large system and small program segments; Provides documentation; It makes coding easier.

Flowcharting Disadvantages 1. 2. 3. 4. It It It It can be time-consuming and difficult to construct; can be unwieldy; is hard to modify; can be challenging to design.

Flowcharting Symbols 1. Input/Output Symbol (Parallelogram) Indicates where the data are to be entered (input) or results to be displayed (output). 2. Processing Symbol (Rectangle) use to represent a group of program instructions that perform a processing function of the program such as arithmetic operation, comparing, sorting, and etc. 3. Decision Symbol (Diamond) denotes a choice or decision to be made by the computer. It is used to document a point in the program where more than one path can be taken (alternative paths is possible). 4. Preparation/Initialization Symbol (Hexagon) Initialize or store the first values of the variables. 5. Terminal Symbol (Oval) use to designate the beginning and the end of a program, or point of interruption. 6. On-page Connector (Small Circle) it is use to connect various subparts of a flowchart. This circle can contain a number or letter. The sequence of instruction continues to another on page connector which has the same number or letter. 7. Flow Direction Indicators (Arrowheads) use to show the direction of processing or data flow. 8. Off-page connector (Small Pentagon) this type of connector is use instead of the on-page connector to designate the entry to or exit from the page when flowchart requires more than one page. 9. Flow lines (Horizontal/Vertical Lines) use to show reading order or sequence in which flowchart symbols are to be read.

Input/Output

Processing

Decision

Preparation

Terminal

On-page Connector

Flow Direction Indicator

Off-page Connector

Flow Lines

Operators (Notations) Applied in Flowcharting Mathematical Operators + * / Mod Addition Subtraction Multiplication Division Modulus Relational Operators > < = >= <= <> greater than less than equal to greater than or equal to less than or equal to not equal to Logical Operators AND OR NOT

Example 1: Create an algorithm that computes and prints the area of a circle. Use the formula: A=r2 where Pi() is approximately equivalent to 3.1416. Example 2: Create an algorithm that computes and prints out the sum, average, and the product of three numbers.

1. Read three numbers, call them variables num1, num2, and num3 respectively 2. Determine the sum of the three numbers then store the results in variable
SUM. 3. Compute the average of the three numbers by dividing variable SUM by 3, store the result in variable AVE. 4. Multiply the three numbers then store the result in PROD variable. 5. Print out the computed values: SUM, AVE, and PROD

Example 3: Given two numbers X and Y create an algorithm to determine the difference between X and Y. If X-Y is negative, compute R=X+Y; if X-Y is zero, compute R=2X+2Y; and if X-Y is positive, compute R=X*Y. Print out the values of X, Y, and R. 1. Read two numbers call them variable X and Y 2. Subtract X from Y, and then store the result in variable DIFF. 3. If DIFF is negative compute R=X+Y; if zero, compute R=2X+2Y; and if it is positive compute R=X*Y 4. Print out values of X, Y and R Example 4: Input two numbers, A and B, If A>B perform subtraction; if A<B perform addition; and if A=B perform multiplication. Store the result in N. Create an algorithm and design a flowchart for this problem. Example 5: REM Manufacturing Corporation plans to give out a year-end bonus for each of its employees. Create an algorithm and draw the flowchart, which will compute for bonus of an employee. Consider the following criteria: If employee has a monthly salary of less than P 8,000, then bonus will be 55% of his monthly salary. However if he has a salary greater than P 8,000 then he gets P 90% of his salary as his/her bonus. Print out the name and corresponding bonus for the employee. Example 6: Create an algorithm and design a flowchart for a problem that will accept three numbers and print out the numbers and the largest.

Vous aimerez peut-être aussi