P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

Chapter 2: Understanding Structure
3 Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. Conditions can be formed using the.
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Introduction to Flowcharting
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.
An Object-Oriented Approach to Programming Logic and Design
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Programming Logic and Design Seventh Edition
Programming Logic and Design, Third Edition Comprehensive
Programming Logic and Design Seventh Edition
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Chapter 3 Planning Your Solution
The Program Design Phases
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
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.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
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.
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
5-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Programming Structure
CHAPTER 2: Understanding Structure. Objectives 2  Learn about the features of unstructured spaghetti code  Understand the three basic structures: sequence,
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
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.
Programming Logic and Design Fifth Edition, Comprehensive
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Algorithms and Pseudocode
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
An Object-Oriented Approach to Programming Logic and Design Second Edition Chapter 2 Understanding Structure.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
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.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Chapter 3 Structured Program Development in C C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
Control Flow (Python) Dr. José M. Reyes Álamo.
Learning outcomes 5 Developing Code – Using Flowcharts
ALGORITHMS AND FLOWCHARTS
Programming Logic and Design Seventh Edition
Programming Logic and Design Eighth Edition
Introduction To Flowcharting
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Programming Fundamentals
Lecture 4B More Repetition Richard Gesick
Using the Priming Read Priming read (or priming input):
A Beginner’s Guide to Programming Logic, Introductory
Understanding the Three Basic Structures
Chapter 8: More on the Repetition Structure
Data and Flowcharts Session
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.
Flow of Control.
Data and Flowcharts Session
Introduction to Computer Science
REPETITION Why Repetition?
Presentation transcript:

P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2

Understanding structure 1 Sequence, Selection, Loop 2 Unstructured Logic 3 Today’s Overview

Learning Objectives Explain structure, sequences, selection and loops

L ECTURE : U NDERSTANDING STRUCTURE

Structure From your homework week 1, you should have understood how important it is to write all programs logically, and to think of every step that would need to be included, and in what sequence. Imagine a program more complicated than your favorite recipe and all the steps.

Structure Think of all the decisions and possibilities involved in a software like PhotoShop Designing the logic would be very time consuming It would be easy to create a mess Logically snarled program statements are called spaghetti code

Structure If a program is using spaghetti code logic, we call them unstructured programs; they are not following the rules of logic

Structure Think of explaining to someone unfamiliar with the process how to brush their teeth How important is sequence? How important is each step?

L ECTURE : S EQUENCE, SELECTION, LOOP

Structure Three basic structures: – Sequence – Selection – Loop Any program, no matter how complicated can, be constructed using one or more of the three

Structure A structure is a basic unit of programming logic and consists of either a sequence, selection, or loop You can diagram any task with these 3

Structure A selection structure asks a question, then depending on the answer, one of two course of actions is performed No matter which path selected, you continue with the next task This is an if-then-else statement

Structure A loop structure repeats actions as long as a condition remains true The action(s) occurring within the loop is known as the loop body Some programmers call this a while..do, or a while loop

Structure Commonly, a condition is evaluated and if the result is true, you execute the loop body If it is still true, you execute again It continues until the condition is false Programmers call this repetition or iteration

Structure These three – sequence, selection, loop – can be combined in any number of ways Each structured program’s segments would be either a sequence, selection or loop Each structure has one entry and one exit

Understanding Structure A structured program has the following characteristics: – Only includes a combination of one of the three basic structures – Can be stacked or connected at only one entry or exit point – Any structure can be nested within another

Understanding Structure Attaching structures end to end is called stacking structures End-structure statements use endif or endwhile statements Endif shows where the actions will end if condition isn’t meant The instructions occur when if is tested true

Structure Any statement that follows the endif statement is outside the decision structure Similarly, endwhile statements show where a loop structure ends Any statements following would be outside of the loop, not part of it

Structure When writing pseudocode, the convention is to align an if with its else then indent any dependent statements a few spaces You would also align a while and an endwhile pair

Structure Besides stacking structures, you can take individual tasks or steps and replace them with additional structures This is called nesting structures A group of statements that executes as a single unit is called a block

Understanding Structure For a program to be structured and work the way you want, you sometimes need to add extra steps A priming input or priming read is the statement that reads the first value in a program It is one kind of added step

Understanding Structure Possible combinations of logical structures are endless but each of a structured program’s segments is a sequence, a selection, or a loop Structured, the flow of logic returns to the eof question Asking yourself this can help determine if your logic is structured

Understanding Structure Remember chapter one’s doubling problem? The input originalNumber was a case of priming input Priming gets the process going Its purpose is to control the loop that begins with the eof question

Understanding Structure Keeping within the sequence, selection, and loop structures creates – Clarity, to make large programs manageable – Professionalism, it is the way it is done – Efficiency, most newer computer languages are structured and use syntax to sequence, select and loop

Understanding Structure Keeping within the sequence, selection, and loop structures creates – Maintenance, for you and others to modify and maintain – Modularity, as they can be easily broken down into routines or modules

Recognizing structure and unstructured logic – Is it constructed from one of the three basic structures? – Does each task follows to the next? – Either through a flowchart or by writing the pseudocode, you should see alternating sequences, but always one of the three basic

Discussion As a group, using the whiteboard, write the pseudocode and flowchart to wash a dog

Homework Write the pseudocode for Ex 2 a-e, and read, Chapter 2. Your solutions will be presented to the class next week