Method & Tools for Program Analysis & Design

Similar documents
A Beginner s Guide to Programming Logic, Introductory

Programming Logic and Design Seventh Edition

Programming Logic and Design Ninth Edition

ALGORITHMS AND FLOWCHARTS

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

BIL101E: Introduction to Computers and Information systems Lecture 8

Lecture 7 Tao Wang 1

CSC 121 Spring 2017 Howard Rosenthal

Computer System and programming in C

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

A Quick Review of Chapter 1

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Fourth Edition

Chapter 1: Problem Solving Skills Introduction to Programming GENG 200

Pseudo Code and Flow Charts. Chapter 1 Lesson 2

APPENDIX E SOLUTION TO CHAPTER SELF-TEST CHAPTER 1 TRUE-FALSE FILL-IN-THE-BLANKS

FLOW CHART AND PSEUDO CODE

Chapter 2: Understanding Structure. Programming Logic and Design, 4 th Edition Introductory

Introduction to Programming

Chapter 3 Structured Program Development

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

Scheme of work Cambridge International AS & A Level Computing (9691)

Module 1: Introduction to Computers, Programs, and Java

SNS COLLEGE OF ENGINEERING,

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

بسم اهلل الرمحن الرحيم

Numerical Methods in Scientific Computation

PLD Semester Exam Study Guide Dec. 2018

PROGRAM DESIGN TOOLS. Algorithms, Flow Charts, Pseudo codes and Decision Tables. Designed by Parul Khurana, LIECA.

Structured Program Development in C

Class 8 ALGORITHMS AND FLOWCHARTS. The City School

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

INTRODUCTION TO ALGORITHMS

S/W Programming & Languages

An Introduction to Programming with C++ Sixth Edition. Chapter 8 More on the Repetition Structure

FLOWCHARTS A flowchart is a graphical representation of the steps to be followed for solving problem. It consists of a set of symbols.

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

Homework #2. If (your ID number s last two digits % 6) = 0: 6, 12, 18

CHAPTER 2 PROBLEM SOLVING TECHNIQUES. Mr Mohd Hatta Bin Hj Mohamed Ali Computer Programming BFC2042


Programming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Chapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1

Chapter 3: Modules. Starting Out with Programming Logic & Design. Second Edition. by Tony Gaddis

Chapter 5: Loops and Files

FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT III. 2 Marks PROBLEM SOLVING AND OFFICE AUTOMATION

1. The first step that programmers follow when they solve problems is to plan the algorithm.

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

SE Assignment III. 1. List and explain primitive symbols used for constructing DFDs. Illustrate the use of these symbols with the help of an example.

5 The Control Structure Diagram (CSD)

Theory of control structures

Problem Solving FLOWCHART. by Noor Azida Binti Sahabudin Faculty of Computer Systems & Software Engineering

A Beginner s Guide to Programming Logic, Introductory. Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

Selection Structures II

PSEUDOCODE AND FLOWCHARTS. Introduction to Programming

Chapter 4: Writing and Designing a Complete Program. Programming Logic and Design, Third Edition Introductory

Chapter 8 Statement-Level Control Structures

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

Chapter 8. Statement-Level Control Structures

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

IDENTIFY WAYS OF REPRESENTING ALGORITHMS.

REPETITION CONTROL STRUCTURE LOGO

Structured Program Development

Information Science 1

Chapter 2 - Control Structures

Top Down Design. 2. Design Methodology

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Lecture Notes for Chapter 2: Getting Started

Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

IS 0020 Program Design and Software Tools

SNS COLLEGE OF ENGINEERING

Steps to program development

Introduction to Flowcharting

Chapter 5 Conditional and Iterative Statements. Statement are the instructions given to the computer to perform any kind of action.

Chapter 1: An Overview of Computers and Logic

Basic Flowchart Symbols and Meaning

Programming for Engineers Iteration

Fundamentals of Programming. Lecture 6: Structured Development (part one)

Structure of Programming Languages Lecture 5

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #01 Introduction: The Process of Programming

12/30/2013 S. NALINI,AP/CSE

Programming revision. Revision tip: Focus on the things you find difficult first.

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

Unit II. (i) Computer Programming Languages

Procedural Programming

Chapter 2 - Problem Solving

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.

Procedural Programming

Programming Logic and Design Sixth Edition

Lesson 1 Python: Interactive Fiction

Introduction to Modules. Chapter 3. Defining and Calling a Module. Introduction to Modules. 5 Benefits of Modules. Modules CSUS, Spring 2016

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators


Information Science 1

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

depicts pictorially schematic representation of an algorithm document algorithms. used in designing or documenting

PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation.

Transcription:

Method & Tools for Program Analysis & Design TMB208 Pemrograman Teknik Kredit: 3 (2-3) 1 Programming Logic and Design, Introductory, Fourth Edition 2 1

Programming Methods Based on structures of programming logic Top Down Method Bottom-Up Method Used structured charts to describe the program logic 3 Structured Programming Structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. Three types of control flow are used: sequential, test, and iteration. a basic unit of programming logic Structure: is a basic unit of programming logic Programming Logic and Design, Introductory, Fourth Edition 4 2

Top Down Design Top Down Design is a method of designing something that starts with the complete item then breaks it down into smaller and smaller components. In programming it means breaking a difficult task down (divide and conquer) and solving pieces independently until every step can easily be implemented (successive refinement). Programming Logic and Design, Introductory, Fourth Edition 5 Advantages of Top-Down Design Breaking the problem into parts helps us to clarify what needs to be done. At each step of refinement, the new parts become less complicated and, therefore, easier to figure out. Parts of the solution may turn out to be reusable. Breaking the problem into parts allows more than one person to work on the solution. 3

Structured Programs We will use top-down design for all remaining programming projects. This is the standard way of writing programs. Programs produced using this method and using only the three kinds of control structures, sequential, selection and repetition, are called structured programs. Structured programs are easier to test, modify, and are also easier for other programmers to understand. Another Example Problem: Write a program that draws this picture of a house. 4

The Top Level the outline of the house the chimney the door the windows Main Outline Chimney Door Windows Pseudocode A natural language for specific purpose with limited & specific grammar & vocabulary Programming Logic and Design, Introductory, Fourth Edition 10 5

Pseudocode for Main Call Outline Call Chimney Call Door Call Windows Observation The door has both a frame and knob. We could break this into two steps. Main Outline Chimney Door Windows Door Frame Knob 6

Pseudocode for Door Call Door Frame Call Knob Another Observation There are three windows to be drawn. Main Outline... Windows Window 1 Window 2 Window 3 7

One Last Observation But don t the windows look the same? They just have different locations. So, we can reuse the code that draws a window. Simply copy the code three times and edit it to place the window in the correct location, or Use the code three times, sending it the correct location each time (we will see how to do this later). This is an example of code reuse. Reusing the Window Code Main Outline... Windows a Window CMSC 104, Version 9/01 16 8

Pseudocode for Windows Call a Window, sending in Location 1 Call a Window, sending in Location 2 Call a Window, sending in Location 3 CMSC 104, Version 9/01 17 Another Level? Should any of these steps be broken down further? Possibly. How do I know? Ask yourself whether or not you could easily write the algorithm for the step. If not, break it down again. When you are comfortable with the breakdown, write the pseudocode for each of the steps (modules) in the hierarchy. Typically, each module will be coded as a separate function. Programming Logic and Design, Introductory, Fourth Edition 18 9

Bottom-up Produces smaller and more flexible programs Promotes code re-use Permits assessment of sub-modules Best suited when problem is ill-defined or missing Programming Logic and Design, Introductory, Fourth Edition 19 Tools for Program Analysis & Design Structured Charts: using graphical diagrams/charts to express programming logic Pseudocode: using narrative symbols to express programming logic 20 10

A set of inputs A set of outputs A Process View of An Algorithm A process is depicted as a circle and has a name A process is representing an algorithm that transforms a set of inputs into a set of ouputs A B C ABC -Program X1 X2 21 Understanding the Three Basic Structures of Programming Logic Any program can be constructed from only three basic types of structures 1. Sequence 2. Selection 3. Loop Programming Logic and Design, Introductory, Fourth Edition 22 11

Understanding the Three Basic Structures (continued) Sequence structure A set of instructions, performed sequentially with no branching Programming Logic and Design, Introductory, Fourth Edition 23 Calculate the area below Milai Start x, y, z L1 x L2 r L3 z r = (x 2 + y 2 ) 0.5 L1 = x 2 y L2= x y /2 L3 = r z / 2 LTOTAL = L1+L2+L3 Write the program code LTOTAL Selesa Stop i Programming Logic and Design, Introductory, Fourth Edition 24 12

Understanding the Three Basic Structures (continued) Selection structure Asks a question, then takes one of two possible courses of action based on the answer Also called a decision structure or an if-then-else Programming Logic and Design, Introductory, Fourth Edition 25 Understanding the Three Basic Structures (continued) Dual-alternative if: contains two alternatives Programming Logic and Design, Introductory, Fourth Edition 26 13

Understanding the Three Basic Structures (continued) Single-alternative if: contains one alternative Programming Logic and Design, Introductory, Fourth Edition 27 Understanding the Three Basic Structures (continued) Single-alternative if Else clause is not required Null case: situation where nothing is done Programming Logic and Design, Introductory, Fourth Edition 28 14

Understanding the Three Basic Structures (continued) Loop structure Repeats a set of actions based on the answer to a question Also called repetition or iteration Question is asked first in the most common form of loop Programming Logic and Design, Introductory, Fourth Edition 29 Understanding the Three Basic Structures (continued) Loop structure Programming Logic and Design, Introductory, Fourth Edition 30 15

Understanding the Three Basic Structures (continued) All logic problems can be solved using only these three structures Structures can be combined in an infinite number of ways Stacking: attaching structures end-to-end End-structure statements Indicate the end of a structure endif: ends an if-then-else structure endwhile: ends a loop structure Programming Logic and Design, Introductory, Fourth Edition 31 Understanding the Three Basic Structures (continued) Programming Logic and Design, Introductory, Fourth Edition 32 16

Understanding the Three Basic Structures (continued) Any individual task or step in a structure can be replaced by a structure Nesting: placing one structure within another Indent the nested structure s statements Block: group of statements that execute as a single unit Programming Logic and Design, Introductory, Fourth Edition 33 Understanding the Three Basic Structures (continued) Programming Logic and Design, Introductory, Fourth Edition 34 17

Understanding the Three Basic Structures (continued) Programming Logic and Design, Introductory, Fourth Edition 35 Understanding the Three Basic Structures (continued) Programming Logic and Design, Introductory, Fourth Edition 36 18

Understanding the Three Basic Structures (continued) Each structure has one entry and one exit point Structures attach to others only at entry or exit points Programming Logic and Design, Introductory, Fourth Edition 37 Flowchart Symbols Basic Name Symbol Use in Flowchart Oval Denotes the beginning or end of the program Parallelogram Denotes an input operation Rectangle Denotes a process to be carried out e.g. addition, subtraction, division etc. Diamond Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE) Hybrid Denotes an output operation Flow line Denotes the direction of logic flow in the program 19

Example N START Input M1,M2,M3,M4 GRADE (M1+M2+M3+M4)/4 IS GRADE<5 0 Y Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print FAIL else Print PASS endif PRINT PASS PRINT FAIL STOP Understanding the Reasons for Structure Advantages of structure: Provides clarity Professionalism Efficiency Ease of maintenance Supports modularity Programming Logic and Design, Introductory, Fourth Edition 40 20

Understanding the Reasons for Structure (continued) Programming Logic and Design, Introductory, Fourth Edition 41 Understanding the Reasons for Structure (continued) Programming Logic and Design, Introductory, Fourth Edition 42 21

Recognizing Structure Any set of instructions can be expressed in structured format Is this flowchart structured? Programming Logic and Design, Introductory, Fourth Edition 43 Recognizing Structure (continued) Is this flowchart structured? Programming Logic and Design, Introductory, Fourth Edition 44 22

Recognizing Structure (continued) To make it structured, pull each symbol out and rework B begins a selection structure Programming Logic and Design, Introductory, Fourth Edition 45 Recognizing Structure (continued) Pull up on the flowline from the left side of B Programming Logic and Design, Introductory, Fourth Edition 46 23

Recognizing Structure (continued) Next, pull up the flowline on the right side of B Programming Logic and Design, Introductory, Fourth Edition 47 Recognizing Structure (continued) Pull up the flowline on the left side of D and untangle it from the B selection by repeating C Programming Logic and Design, Introductory, Fourth Edition 48 24

Recognizing Structure (continued) Now pull up the flowline on the right side of D Programming Logic and Design, Introductory, Fourth Edition 49 Recognizing Structure (continued) Bring together the loose ends of D and of B Programming Logic and Design, Introductory, Fourth Edition 50 25

Nested Using nested if-then-else for multiple alternatives Programming Logic and Design, Introductory, Fourth Edition 51 Three Special Structures Case, Do While, and Do Until Many languages allow three additional structures: case structure do-while structure do-until structure Case Structure: Decisions with more than two alternatives Tests a variable against a series of values and takes action based on a match Nested if-then-else statements will do what a case structure does Programming Logic and Design, Introductory, Fourth Edition 52 26

Three Special Structures Case Using a case structure for multiple alternatives Programming Logic and Design, Introductory, Fourth Edition 53 Three Special Structures Do While, and Do Until do-while and do-until loops Question is asked at the end of the loop structure Ensures that the loop statements are always used at least once Programming Logic and Design, Introductory, Fourth Edition 54 27

Three Special Structures Do While, and Do Until do-while loop executes as long as the question s answer is Yes or True do-until loop executes as long as the question s answer is No or False (until it becomes Yes or True) Programming Logic and Design, Introductory, Fourth Edition 55 Three Special Structures While (Pretest & Posttest Loop) while loop with question at beginning is called a pretest loop while loop with question at end are called posttest loops Programming Logic and Design, Introductory, Fourth Edition 56 28

Pretest Loop Using While Programming Logic and Design, Introductory, Fourth Edition 57 Posttest Loop Using While Programming Logic and Design, Introductory, Fourth Edition 58 29