Programming Logic and Design Eighth Edi(on



Similar documents
2. Capitalize initial keyword In the example above, READ and WRITE are in caps. There are just a few keywords we will use:

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Flowcharting, pseudocoding, and process design

ALGORITHMS AND FLOWCHARTS

Flowchart Techniques

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

Notes on Algorithms, Pseudocode, and Flowcharts

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming

Chapter 12 Programming Concepts and Languages

Pseudo code Tutorial and Exercises Teacher s Version

2667A - Introduction to Programming

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

COWLEY COLLEGE & Area Vocational Technical School

JavaScript: Control Statements I

So#ware quality assurance - introduc4on. Dr Ana Magazinius

Java Application Developer Certificate Program Competencies

Enterprise. Thousands of companies save 1me and money by using SIMMS to manage their inventory.

Some Naming and Coding Standards

Problem Solving Basics and Computer Programming

Introduc)on to the IoT- A methodology

Algorithms are the threads that tie together most of the subfields of computer science.

Algorithms, Flowcharts & Program Design. ComPro

COMPUTER PROGRAMMING DCSA 1303 SCHOOL OF SCIENCE AND TECHNOLOGY

Strategies for Medical Device So2ware Development Presented By Anthony Giles of Blackwood Embedded Solu;ons And a Case Study by Francis Amoah of Creo

Fundamentals of Programming and Software Development Lesson Objectives

Software Engineering Techniques

Python Programming: An Introduction To Computer Science

PL / SQL Basics. Chapter 3

2 SYSTEM DESCRIPTION TECHNIQUES

Chapter 13: Program Development and Programming Languages

Two-way selection. Branching and Looping

What Is Recursion? 5/12/10 1. CMPSC 24: Lecture 13 Recursion. Lecture Plan. Divyakant Agrawal Department of Computer Science UC Santa Barbara

Data Mining. Supervised Methods. Ciro Donalek Ay/Bi 199ab: Methods of Sciences hcp://esci101.blogspot.

Introduction to Python

WebSphere Commerce V7 Feature Pack 2

CS 241 Data Organization Coding Standards

HOW TO CREATE APPS FOR TRAINING. A step- by- step guide to crea2ng a great training app for your company

Outline. Setting the Stage. Se#ng the stage for precep0ng drug therapy assessment Elements of drug therapy assessment Hierarchy Flow chart

Chapter 1 An Introduction to Computers and Problem Solving

Chapter 3. Database Architectures and the Web Transparencies

Modeling, Computers, and Error Analysis Mathematical Modeling and Engineering Problem-Solving

Software development and programming. Software

Kaseya Fundamentals Workshop DAY THREE. Developed by Kaseya University. Powered by IT Scholars

Summary of the MARIE Assembly Language

Specimen 2015 am/pm Time allowed: 1hr 30mins

Conditionals: (Coding with Cards)

2010 Software Development GA 3: Written examination

Different Approaches to White Box Testing Technique for Finding Errors

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Decision Logic: if, if else, switch, Boolean conditions and variables

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

CSC 221: Computer Programming I. Fall 2011

Programming and Software Development CTAG Alignments

Software Design and Development

Programmable Logic Controllers Definition. Programmable Logic Controllers History

Advanced Project Management Training Course

Introduction to Computers and Programming. Testing

Experiments on cost/power and failure aware scheduling for clouds and grids

4.8 Thedo while Repetition Statement Thedo while repetition statement

Chapter 13: Program Development and Programming Languages

Computer Programming

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

Sourcing Strategy: Oracle ULA. ITALCONSOR Procurement Consultants

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

Database Programming with PL/SQL: Learning Objectives

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

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

COMPUTER SCIENCE (5651) Test at a Glance

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

Visual Logic Instructions and Assignments

Curriculum Map. Discipline: Computer Science Course: C++

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Understanding Data Flow Diagrams Donald S. Le Vie, Jr.

Information technology Programming languages Fortran Enhanced data type facilities

Achieving Global Cyber Security Through Collaboration

VB Controls and Events. Introduc)on. Program Planning and Flowcharts Visual Basic Visual basic Interface VB Controls CreaGng a Project

C A R I B B E A N E X A M I N A T I O N S REPORT ON CANDIDATES S WORK IN THE CARIBBEAN SECONDARY EDUCATION CERTIFICATE EXAMINATION MAY/JUNE 2012

Software Development. Topic 1 The Software Development Process

An Introduction to the WEB Style of Literate Programming

Computer Programming

Transcription:

Programming Logic and Design Eighth Edi(on Chapter 3 Understanding Structure

Objec3ves In this chapter, you will learn about: The disadvantages of unstructured spaghea code The three basic structures sequence, selec3on, and loop Using a priming input to structure a program The need for structure Recognizing structure Structuring and modularizing unstructured logic 2

The Disadvantages of Unstructured Spaghe' code SpagheA Code Logically snarled program statements OKen a complicated mess Programs oken work but are difficult to read and maintain Confusing and prone to error Unstructured programs Do not follow the rules of structured logic Structured programs Follow the rules of structured logic 3

Figure 3-1 SpagheA code logic for washing a dog 4

Understanding the Three Basic Structure Structures Basic unit of programming logic Sequence structure Perform ac3ons or tasks in order No branching or skipping any task Selec:on structure (decision structure) Ask a ques3on, take one of two ac3ons OKen called if- then- else Dual- alterna:ve ifs or single- alterna:ve ifs Loop structure Repeat ac3ons while a condi3on remains true 5

Understanding the Three Basic Structures (con3nued) Figure 3-2 Sequence structure 6

Understanding the Three Basic Structures (con3nued) Figure 3-3 Selec3on structure 7

Understanding the Three Basic Dual- alterna:ve ifs Structures (con3nued) Contains two alterna3ves The if-then-else structure if somecondition is true then else endif do oneprocess do theotherprocess 8

Understanding the Three Basic Structures (con3nued) Single- alterna:ve ifs if employee belongs to dentalplan then deduct $40 from employeegrosspay An else clause is not required null case Situa3on where nothing is done 9

Understanding the Three Basic Structures (con3nued) Figure 3-4 Single- alterna3ve selec3on structure 10

Understanding the Three Basic Structures (con3nued) Loop structure Repeats a set of ac3ons while a condi3on remains true Loop body Also called repe::on or itera:on Condi3on is tested first in the most common form of loop The while do or while loop 11

Understanding the Three Basic Structures (con3nued) Figure 3-5 Loop structure 12

Understanding the Three Basic Structures (con3nued) Loop structure while testcondition continues to be true do someprocess endwhile while you continue to be hungry take another bite of food determine if you still feel hungry endwhile 13

Understanding the Three Basic Structures (con3nued) All logic problems can be solved using only sequence, selec3on, and loop Structures can be combined in an infinite number of ways Stacking structures A_aching structures end- to- end End- structure statement Indicates the end of a structure The endif statement ends an if-then-else structure The endwhile statement ends a loop structure 14

Understanding the Three Basic Structures (con3nued) Figure 3-6 Structured flowchart and pseudocode with three stacked structures 15

Understanding the Three Basic Structures (con3nued) Any individual task or step in a structure can be replaced by a structure Nes:ng structures Placing one structure within another Indent the nested structure s statements Block A group of statements that execute as a single unit 16

Understanding the Three Basic Structures (con3nued) Figure 3-7 Flowchart and pseudocode showing nested structures a sequence nested within a selec3on 17

Understanding the Three Basic Structures (con3nued) Figure 3-8 Flowchart and pseudocode showing nested structures a loop nested within a sequence, nested within a selec3on 18

Understanding the Three Basic Structures (con3nued) Figure 3-9 Flowchart and pseudocode for a selec3on within a loop within a sequence within a selec3on 19

Understanding the Three Basic Structures (con3nued) Structured programs have the following characteris3cs: Include only combina3ons of the three basic structures Each structure has a single entry point and a single exit point Structures can be stacked or connected to one another only at their entry or exit points Any structure can be nested within another structure 20

Using a Priming Input to Structure a Program Priming input (or priming read) Reads the first input data record Is outside the loop that reads the rest of the records Helps keep the program structured Analyze a flowchart for structure one step at a 3me Watch for unstructured loops that do not follow this order First ask a ques3on Take ac3on based on the answer Return to ask the ques3on again 21

Using a Priming Input to Structure a Program (con3nued) Figure 3-14 Structured, but nonfunc3onal, flowchart of number- doubling problem 22

Using a Priming Input to Structure a Program (con3nued) Figure 3-15 Func3onal but unstructured flowchart 23

Figure 3-16 Func3onal, structured flowchart for the number- doubling problem 24

Figure 3-17 Structured but incorrect solu3on to the number- doubling problem 25

Understanding the Reasons for Structure Clarity unstructured programs are confusing Professionalism other programmers expect it Efficiency most languages support it Maintenance other programmers find it easier to read Modularity easily broken down into modules 26

Recognizing Structure Structured Flowcharts? Figure 3-18 Example 1 Figure 3-19 Example 2 27

Recognizing Structure (con3nued) An Unstructured Flowchart Figure 3-20 Example 3 28

Recognizing Structure (con3nued) Figure 3-21 Steps to structure the dog- washing process 29

Recognizing Structure (con3nued) Figure 3-22 Structured dog- washing flowchart and pseudocode 30

Recognizing Structure (con3nued) Figure 3-23 Modularized version of the dog- washing program 31

Summary SpagheA code Statements that do not follow rules of structured logic Three basic structures Sequence, selec3on, and loop Combined by stacking and nes3ng Priming input Statement that reads the first input value prior to star3ng a structured loop 32

Summary (con3nued) Structured techniques promote: Clarity Professionalism Efficiency Modularity Flowcharts can be made structured by untangling Logical steps can be rewri_en to conform to the three structures 33