Programming Structure

Slides:



Advertisements
Similar presentations
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Advertisements

Microsoft® Small Basic
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
CS107 Introduction to Computer Science Lecture 2.
Chapter 2: Understanding Structure
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
CS 111: Introduction to Programming Midterm Exam NAME _________________ UIN __________________ 10/30/08 1.Who is our hero? 2.Why is this person our hero?
3.1.3 Program Flow control_1 Understand the need for structure Breaking things down.
Introduction to Flowcharting
PSEUDOCODE & FLOW CHART
Selection (decision) control structure Learning objective
Understanding the Three Basic Structures
An Object-Oriented Approach to Programming Logic and Design
UNIT 3 PROBLEM SOLVING WITH LOOP AND CASE LOGIC STRUCTURE
 Control structures  Algorithm & flowchart  If statements  While statements.
Programming Logic and Design Seventh Edition
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
CSC103: Introduction to Computer and Programming
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Programming Logic and Design Fourth Edition, Introductory
C++ If….Else Statements and Flowcharts October 10, 2007.
Selection Control Structure. Topics Review sequence control structure Structure theorem Selection control structure If statement Relational operators.
1 Loops. 2 Topics The while Loop Program Versatility Sentinel Values and Priming Reads Checking User Input Using a while Loop Counter-Controlled (Definite)
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Programming with Microsoft Visual Basic th Edition
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
CHAPTER 2: Understanding Structure. Objectives 2  Learn about the features of unstructured spaghetti code  Understand the three basic structures: sequence,
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
CS 100 Introduction to Computing Seminar October 7, 2015.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
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.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
Chapter 7 Problem Solving with Loops
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
Logical Thinking CS 104 9/12/11. Agenda Today  College Board survey reminder  Note: Simple “how to” guide on Scratch posted on eLearning  Review HW.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Programming Logic and Design Fifth Edition, Comprehensive
Algorithms and Pseudocode
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 4 Making Decisions.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Structured Programming The Basics
Programming Logic and Design Seventh Edition
Chapter 3: Decisions and Loops
PROGRAM CONTROL STRUCTURE
Transition to Code Upsorn Praphamontripong CS 1110
Chapter 5: Control Structure
Programming Logic and Design Eighth Edition
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Chapter 5: Repetition Structures
Transition to Code Upsorn Praphamontripong CS 1111
Using the Priming Read Priming read (or priming input):
A Beginner’s Guide to Programming Logic, Introductory
Structured Program
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Understanding the Three Basic Structures
Chapter 8: More on the Repetition Structure
Three Special Structures – Case, Do While, and Do Until
ICT Gaming Lesson 2.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Presentation transcript:

Programming Structure CS 104 9/7/11

Agenda Go over Quiz Quiz #2 9/14 Discuss Assignment #1 due today (11:59pm) Discuss Assignment #2 due 9/21 (11:59pm) Finish slides from Wednesday Introduction to programming logic and BYOB Scratch

Unstructured Code: Spaghetti Code Ferrell, Joyce. Programming Logic and Design, Third Edition Introductory

Three Basic Structures Three basic structures in programming Sequence structure Decision structure Loop structure The design dictates which structures are required

Sequence Structure Sequence: one action occurs after another Most basic structure

Sequence Structure Example Wake up Turn off alarm Eat breakfast Brush teeth Shower Get dressed Pack bookbag Draw a square in Scratch

Decision Structure Just as the name implies, the decision structure requires making a decision A true/false question is asked, and the program chooses one of two paths depending on whether the answer is true or false

Decision Structure Also known as an if-statement or an if-then-statement if condition is true then do processA else do processB It’s possible that only one process exists if car needs gas then get gas

Decision Structure It’s possible that only one process exists if car needs gas then get gas

Decision Statement Example if weather = raining then wear rain boots else wear sandals end if

Decision Statement Example Football score calculator touchdown = 6 extra point = 1 field goal = 3 safety = 2 Modify square program to ask the user if he/she wants to make another square

Looping Also referred to as Iteration or Repetition A question is asked, if the answer is true, the specified action is performed, and the question is asked again Different types of loops Do Until – do the action until the question is true Do While – do the action while the question is true For – repeats a specific number of times

Loop Structure Example while quarter < 5 quarter = quarter + 1 end while Loop the square drawing program

Three Basic Structures Sequence of all three structures Ferrell, Joyce. Programming Logic and Design, Third Edition Introductory

Three Basic Structures Nesting structures can be necessary Sequence within a Decision statement Ferrell, Joyce. Programming Logic and Design, Third Edition Introductory

Why Use Structure? Increases readability Allows for multiple programmers to work on the same program (modularity) Help identify errors more quickly

Flowchart and Pseudocode of Structured College Admission Program Notice how much easier this is to read than the spaghetti code version Ferrell, Joyce. Programming Logic and Design, Third Edition Introductory

Pseudocode for Rock, Paper, Scissors Sequence, Decision, and Looping structures can be used to solve almost any problem Ferrell, Joyce. Programming Logic and Design, Third Edition Introductory

Summary Spaghetti code is unorganized making it difficult to read and maintain Three types of structures: sequence, decision, loop Assignment #2 due 9/21 Quiz #2 9/14 Install BYOB Scratch and start trying it out =)