Planning a Program - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

Planning a Program

Description:

Steps that programmers use to plan a program before they write code. ... Some IDEs identify some errors made in syntax as you type before the code ever gets compiled ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 40
Provided by: pt14
Category:
Tags: ides | planning | program

less

Transcript and Presenter's Notes

Title: Planning a Program


1
Planning a Program
  • HI5100 Data Structures for BioInformatics
  • Lesson 3

2
OBJECTIVES
  • In this lesson you will learn
  • Steps that programmers use to plan a program
    before they write code.
  • How to use the Input-Process-Output model to
    understand parts of programs.

3
Lesson 3 Sections
  • 1.1 Why Plan?
  • 1.2 Stages of Program Planning
  • 1.3 Features of User-Friendly Apps
  • 1.4 Logic Structures Used in Programs
  • 1.5 Summary

4
What is a Computer Program?
  • Step-by-step instructions that tell the computer
    what to do
  • There can be no ambiguity in the statements
  • Thus, strict syntax rules exist for every
    programming language
  • Programs are read one character at a time
  • White space (space, tab, return) separates
    words
  • Words are compared to the rules of the language
    and interpreted (translated into machine language)

5
Simple Sequential Instruction Set
  • Click on the Start button in the lower right hand
    corner of the screen
  • Click on Enterprise Manager icon in the left
    panel to start up Enterprise Manager

6
Sometimes A More Complex Structure of
Instructions is Needed
Where is Enterprise Manager? I dont see it. What
do I do now?
7
More Complex Instruction Set Structure
  • Click on the Start button in the lower right hand
    corner of the screen
  • Do you see an Enterprise Manager icon in the left
    panel?
  • If you answered yes, then click on the icon to
    start up Enterprise Manger
  • If you answered no, then

8
Program Complexity
  • Modern programs often accomplish very complex
    tasks
  • Programs that accomplish complex tasks are very
    complex
  • Thus, the process of creating a program often
    requires significant planning prior to writing

9
Development Stages
  • Analyze
  • Write specifications
  • Design
  • Implement/Debug/Implement
  • Test/Debug/Modify/Test/Debug
  • Deploy and Maintain

10
Analyze the Problem
  • Analyze the problem to be solved
  • Break it down into smaller tasks
  • What input is required?
  • What will be the output?
  • Your goal is to understand the problem from the
    users perspective

11
Write Specifications
  • Describe what the program will do
  • At this stage, you are not planning how it will
    do things
  • Specify inputs
  • Specify outputs
  • Specify how inputs relate to outputs

12
Design the Program
  • Define subtasks and inputs and outputs for each
  • Design flow of data and processing through the
    subtasks
  • Develop the logic of the program
  • Develop algorithms to perform tasks

13
Implement
  • Translate the design into code
  • Use software to compile the program
  • With Python we will use the Python interpreter to
    translate the program line-by-line rather than
    create a compiled version
  • Find syntax errors

14
Typos and syntax errors often occur when
translating a design into code
  • Sources of Error

15
Syntax Errors
  • Every programming language requires that programs
    follow a set of rules for syntax
  • Compilers identify errors made in syntax
  • Some IDEs identify some errors made in syntax as
    you type before the code ever gets compiled

16
Can You Spot An Error in Syntax?
  • Preheat the oven to 350 F.
  • Put the cake mix into a bowl.
  • Add 2 slightly beaten eggs, ¼ c. vegetable oil
    and 1 ½ c. water.
  • Mix for 3 minutes using medium speed of an
    electric mixer.
  • For 33 minutes pour batter into greased pan and
    bake.
  • Remove from oven and let cool.

17
Can You Spot an Error that is most likely a Typo?
  • Preheat the oven to 350 F.
  • Put the cake mix into a bowl.
  • Add 2 slightly beaten eggs, ¼ c. vegetable oil
    and 1 ½ c. water.
  • Mix for 30 minutes using medium speed of an
    electric mixer.
  • Pour batter into greased pan and bake for 33
    minutes.
  • Remove from oven and let cool.

18
Implement
  • Once translated into code and compiled, the
    syntax errors and typos are gone
  • The program will not execute if there are syntax
    errors and typos
  • Input into the computer for testing
  • The apps we create can only run on a program that
    has the Python interpreter installed
  • If we compiled them down to .exe form, then they
    could run on any computer with the appropriate OS

19
Test and Debug
  • Testing and debugging of complex programs should
    be integrated with implementation
  • During coding, you are testing for typos and
    syntax errors
  • After typos and syntax errors are gone, there
    still can be errors

20
Errors in Logic
  • The program runs, but the output is not correct
    with respect to the problem the program is
    supposed to solve

21
No Syntax Errors, No Typos, No Logical Design
  • Mix for 3 minutes using medium speed of an
    electric mixer.
  • Preheat the oven to 350 F.
  • Pour batter into greased pan and bake for 33
    minutes.
  • Put the cake mix into a bowl.
  • Remove from oven and let cool.
  • Add 2 slightly beaten eggs, ¼ c. vegetable oil
    and 1 ½ c. water.

22
Deploy and Maintain
  • When the program is thoroughly tested and revised
    based on testing, it is ready to be employed by
    users to accomplish tasks
  • Often new programs are deployed to a small pilot
    group of typical users
  • Pilot users provide feedback
  • Suggestions for improvement
  • Bugs not found during testing
  • Provide all users with patches and updates

23
User-Friendly Programs
  • Modern applications employ a GUI (graphical user
    interface)
  • At this point, we will not begin investigating
    how to create GUIs
  • If the user cannot use the program without
    extensive instruction, the program is not
    user-friendly

24
Features for User-Friendliness
  • Print an introduction that tells the user what
    task the program completes
  • Print any instructions the user needs
  • Try to avoid creating a program that can only be
    used after reading a lengthy set of instructions

25
Three Basic Logic Structures for Programming
  • A programming structure is a unit of programming
    logic
  • Three basic structures
  • Sequence
  • Selection ? Decision
  • Loop ? Iteration ? Repetition
  • Computer scientists have shown that you can solve
    any problem of logic using only these three
    structures

26
Sequence
  • Line by line execution
  • Execute line 1, followed by line 2, followed by
    line 3,

27
Sequence
  • Graphical representation
  • Flowchart elements
  • Terminator (oval)
  • Process (rectangle)

28
Selection ? Decision
  • The terms selection and decision are synonyms
    with respect to programming
  • Ask a question
  • Two courses of action can be taken, depending on
    the answer to the question

29
Selection ? Decision
30
Selection ? Decision
  • Decision (diamond)
  • In code, a basic decision structure often
    involves the key words if then - else

31
Loop ? Iteration ? Repetition
  • Repeat a block of code over and over until a
    condition is met
  • Code
  • Decision no
  • Same code
  • Decision no
  • Same code
  • Decision yes
  • Continue with something else

32
Loop ? Iteration ? Repetition
  • The process is performed only if the decision is
    true
  • It continues to be performed until the decision
    is false

33
Additional Logic Structures for Programming
  • While computer scientists have shown that you can
    solve any problem of logic using only the three
    structures of sequence, decision, and loop,
  • Most modern programming languages allow three
    more structures (for each of programming)
  • Case
  • Do While
  • Do Until

34
Case
  • There is a decision variable
  • Case 1 is executed when the decision variable has
    a certain value
  • Case 2 is executed when the decision variable has
    another value
  • Case 3 is executed when the decision variable has
    a third value

35
Case
36
Do While and Do - Until
  • With the basic loop structure, the decision is
    made before the code block is executed
  • Thus the code block may not be executed at all if
    the decision is FALSE originally
  • With do while and do until loops the decision
    is made after the code block is executed at least
    once

37
Do While and Do Until
  • The process is performed and then the decision
    question is evaluated
  • Based on the evaluation result the process is
    repeated or not

38
Summary
  • You are now familiar with some basic ideas about
    how to plan a program and the logic structures
    that are often used in this process
  • Each logic structure has an interpretation in the
    programming language of choice, in our case,
    Python
  • We will look at Python syntax for the basic logic
    structures in the next lesson

39
End of Slides for Lesson 3
  • HI5100 Data Structures for BioInformatics
  • Lesson 2
Write a Comment
User Comments (0)
About PowerShow.com