1 / 19

Programming Structure

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.

xandy
Download Presentation

Programming Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Structure CS 104 9/7/11

  2. 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

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

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

  5. Sequence Structure • Sequence: one action occurs after another • Most basic structure

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

  7. 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

  8. 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

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

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

  11. 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

  12. 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

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

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

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

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

  17. 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

  18. 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

  19. 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 =)

More Related