2 0 Problem Solving PROGRAM DESIGN Prepared by
2. 0 Problem Solving PROGRAM DESIGN Prepared by : Pn Nurul Zakiah Binti Kasnun @ IT Department
STEP 2: PROGRAM DESIGN n Definition: It is a framework or flow that shows the steps in problem solving. n Methods to design a program: Pseudocode ¨ Flowchart ¨ Structure Chart ¨ IPO Chart ¨
Pseudocode n Steps in problem solving that is written half in programming code and half in human language. n For example, some part uses C language code and some part uses Malay or English language. n Advantages: i. iii. n Easily understood. Easily maintained. The codes are changeable. Disadvantages: Cannot be executed in the computer.
Example: START Total=0, Average=0 Input a, b, c Total = a + b + c Average = Total / 3 Output a, b, c Output Average END
Flowchart n A graphical representation of data, information and workflow using certain symbols that are connected to flow lines to describe the instructions done in problem solving. n It shows the flow of the process from the start to the end of the problem solving.
Flowchart START Input Process Output END Explanation Enter data from keyboard Calculate total Display data and total
Explanation of basic flowchart symbol: Simbol / Symbol Penerangan / Explanation Indicate the direction of data flow. Used to connect a block to another block. Flow Lines Indicates operations / process involved. Process Receive Input / Output / read value Display value Execute decision based on condition. Test is performed and the program flow continues, based on the result. Decision Start / End Flow Lines Indicates the beginning and end of a flowchart. Show the continuing flowchart in the same page. On-page connector Flow Lines
START Input True Condition True Statement False statement Output END Symbol usage
Cont…Explanation of basic flowchart symbol: START B Symbol Explanation Input Output Flowchart continues in the next page. Process END Off Page Connector B Next page First page Symbol Usage
There are few additional symbols of flowchart used in a complicated program: GOSUB and RETURN. It’s usually used in a big program. Symbol Explanation Instruct the executed instruction to move to the next function GOSUB Instruct the executed instruction to return to the next instruction after the GOSUB instruction, called the function. RETURN
area START area =22 / 7 * radius Input radius Output area GOSUB area RETURN END Symbol Usage
Example Flowchart: Flowchart to calculate the total of fine for late returning of library books. START Input total_of_day Fine = total_of_day * 0. 20 Output Fine END Symbol Usage
Structure Charts n Structure chart is an additional method in preparing programs that has many sub modules. n It consists rectangular boxes, which represents all the sub modules in a program and is connected by arrows. n It illustrates the top-down design of a program and is also known as hierarchical chart because its components are in hierarchical form. n The advantage is that it is easy to be drawn and to be changed. n Main. Module Format: Sub. Module 1 Sub. Module 2 Sub. Module 3 Sub. Module 2. 2
Example 1: Problem: To calculate the amount of water bill n Water bill Display instructions for user Get / read data Compute the charge Determine the late charge Represent the modules in the program Display the bill Print the bill
Example 2: Problem: To calculate area of a circle n Area of a circle Display instructions for user Get / read data Compute the area Define the area Represent the modules in the program Display the area Print the area
IPO Chart (Input Process Output) Input Process Module Reference No. Output All inputs All Process Module Reference No. from structure chart All outputs
Example : Calculate the Salary of Employee Input Process Hour Pay rate 1. 2. 3. 4. 5. 6. Start Enter hour Enter pay rate Calculate salary Display salary End Module Reference No. Output 0000 1000 Salary 2000 3000 0000
- Slides: 17