CHAPTER 2: Understanding Structure. Objectives 2  Learn about the features of unstructured spaghetti code  Understand the three basic structures: sequence,

Slides:



Advertisements
Similar presentations
Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
Advertisements

More on Algorithms and Problem Solving
Chapter 2: Understanding Structure
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Programming Logic and Design Eighth Edition
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Selection (decision) control structure Learning objective
Understanding the Three Basic Structures
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
Lesson 5 - Decision Structure By: Dan Lunney
An Object-Oriented Approach to Programming Logic and Design
Programming Logic and Design Seventh Edition
Programming Logic and Design Seventh Edition
Chapter 2: Algorithm Discovery and Design
Program Design and Development
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Programming Logic and Design Sixth Edition
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Chapter 3 Making Decisions
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Programming Logic and Design, Second Edition, Comprehensive
Programming Logic and Design Fifth Edition, Comprehensive
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
The world of Constructs Control Structures. The three Structures Sequence Selection Loop Entry Exit.
Programming Structure
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 Chapter 16 Component-Level Design. 2 Component-Level Design  the closest design activity to coding  the approach: review the design description for.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
2 Chapter 21 Understanding Structure Programming Logic and Design, Second Edition, Comprehensive 2.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Programming Logic and Design Fifth Edition, Comprehensive
An Object-Oriented Approach to Programming Logic and Design Second Edition Chapter 2 Understanding Structure.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 4 Making Decisions.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
ALGORITHMS AND FLOWCHARTS
Programming Logic and Design Seventh Edition
REPETITION CONTROL STRUCTURE
Programming Logic and Design Eighth Edition
( Iteration / Repetition / Looping )
Programming Fundamentals
Using the Priming Read Priming read (or priming input):
A Beginner’s Guide to Programming Logic, Introductory
STRUCTURED CONTROL: BASIC CONTROL OPERATORS
Component-Level Design
Understanding the Three Basic Structures
Three Special Structures – Case, Do While, and Do Until
Data and Flowcharts Session
ICT Programming Lesson 3:
Data and Flowcharts Session
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
ICT Gaming Lesson 2.
Program Flow.
Data and Flowcharts Session
Structural Program Development: If, If-Else
Presentation transcript:

CHAPTER 2: Understanding Structure

Objectives 2  Learn about the features of unstructured spaghetti code  Understand the three basic structures: sequence, selection, and loop  Use a priming read  Appreciate the need for structure  Recognize structure  Learn about three special structures: case, do-while, and do-until

Spaghetti Code 3  Spaghetti code: logically snarled program statements  Can be the result of poor program design  Spaghetti code programs often work, but are difficult to read and maintain  Convoluted logic usually requires more code

Structure 4  Structure: basic unit of programming logic  Any program can be constructed from only three basic types of structures  Sequence Perform actions in order No branching or skipping any task  Selection (decision) Ask a question, take one of two actions Dual-alternative or single-alternative  Loop Repeat actions based on answer to a question

Structures Sequence Selection Repeat

Selection  Dual-alternative if: contains two alternatives if someCondition is true then do oneProcess else do theOtherProcess  Single-alternative if if employee belongs to dentalPlan then deduct $40 from employeeGrossPay

Loop  Loop structure while testCondition continues to be true do someProcess while quantityInInventory remains low continue to orderItems

Stacking  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  The endif statement ends an if-then-else structure  The endwhile ends a loop structure

Stacking

Nesting  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

Nesting

IMPORTANT  Each structure has one entry and one exit point  Structures attach to others only at entry or exit points

Using the Priming Read (continued)  Unstructured loop Figure 2-12 Unstructured flowchart of a number-doubling program

Using the Priming Read (continued)  Structured but nonfunctional loop Figure 2-15 Structured, but nonfunctional, flowchart of number-doubling problem

Using the Priming Read (continued)  Functional but nonstructured loop Figure 2-16 Functional, but nonstructured, flowchart

Using the Priming Read (continued)  Functional and structured loop Figure 2-17 Functional, structured flowchart and pseudocode for the number-doubling problem

Using the Priming Read (continued)  Priming read sets up the process so the loop can be structured  To analyze a flowchart’s structure, try writing pseudocode for it start get inputNumber while not eof calculatedAnswer = inputNumber * 2 print calculatedAnswer get inputNumber endwhile stop

Understanding the Reasons for Structure  Provides clarity  Professionalism  Efficiency  Ease of maintenance  Supports modularity