SlideShare a Scribd company logo
Lect 3 P. 1
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Structured Engineering Problem Solving and
Logic Diagrams
Lecture 3
Lect 3 P. 2
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
TOOLS FOR PROGRAM DEVELOPMENT
• A variety of tools and techniques can be used in
the process of program development
• Useful for organizing the tasks in problem
solving
• Many of the tools are focused on the:
– development or formulation of algorithms
– representation of algorithms
– refinement or structuring of algorithms
Lect 3 P. 3
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
TOOLS FOR PROGRAM DEVELOPMENT
• Top-down design technique
– Start with overall function and perform several
step-wise refinements
• Pseudo code
– Artificial and informal language that helps
programmers develop algorithms
• Logic diagrams
– Alternate representations of algorithms
including graphic and state representations
Lect 3 P. 4
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
TOP-DOWN STEPWISE REFINEMENT
• Begin with a single statement that conveys the
overall function of the program. This is a
complete (but simple) representation of the
program.
• Divide this "top" statement into a series of
smaller tasks and list them in the order in which
they must be performed to produce a first
refinement.
Lect 3 P. 5
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
TOP-DOWN STEPWISE REFINEMENT
• Next, refine each of the smaller tasks into yet
smaller steps, defining specific "variables" as
may be needed in this second refinement.
• Continue refinement until algorithm is fully
developed.
• When combined with pseudo code, writing the
program is normally straightforward.
Lect 3 P. 6
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example
• The Problem:
The students in a class have taken their first quiz.
The grades (in the range of 0 to 100) are
available. Determine the class average on the
quiz.
• Givens:
Grades, Possible range of legitimate grades.
Lect 3 P. 7
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example (continued)
• Unknowns:
How many grades to be averaged?
• Assumptions:
A "grade" not in the range of expected grades
could be used to indicate the that all of the
legitimate grades have been entered. (Called
"sentinel" or "flag".)
Lect 3 P. 8
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example (continued)
• Using pseudo code, we begin by representing the
top:
– Determine the class average for the quiz
Lect 3 P. 9
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example (continued)
• Next, perform the first refinement:
– Determine the class average for the quiz
• Initialize variables
• Input, sum, and count quiz grades
• Calculate and print the class average
Lect 3 P. 10
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example (continued)
• Next, refine each one of these smaller tasks:
– Initialize variables
• Initialize a running total to zero
• Initialize a grade counter to zero
Lect 3 P. 11
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example (continued)
Input, sum, and count quiz grades
Input the first grade
While the user has not entered the "flag"
Add this grade into the running total
Add one to the grade counter
Input next grade (possibly the "flag")
Lect 3 P. 12
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Top-Down Example (continued)
Calculate and print the class average
If the grade counter is not zero
Set the class average to the running
total divided by the grade counter
Print the average
Else
Print "No grades were entered"
Lect 3 P. 13
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Handling Special Cases
• Notice that the top-down refinement example
included the handling of a "special case".
• Many of you are aware of the special treatment
that Windows gives to the extreme "special
cases" (sometimes called the BSOD or Blue
Screen of Death…)
Lect 3 P. 14
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Handling Special Cases
Lect 3 P. 15
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Some Types of Logic Diagrams
• Flow Charts -- graphic representation of an
algorithm
– an aid to writing the program
– no formal standards, but common guidelines
• Action Diagrams -- technique for diagramming of
control structures of a program
– an outline of the computer application
– what things happen, when, where, how many
times
Lect 3 P. 16
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Characteristics of Flow Charts
• Useful tool in program development
• Not a complete description of program
• Not only tool to use
• Made before writing the program
• Program might differ from flowchart
• Only executable statements are shown
• Specific equations and tests not included
• Every main and sub-program is charted
Lect 3 P. 17
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
• The commonly used flowcharting symbols follow
• Refer to Section 9 of the H192 "Class Notes" for a
more complete description of the various
flowcharting symbols normally used
Lect 3 P. 18
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
Begin or End a Procedure:
"Main Program" "Subprogram"
Begin
End
START BEGIN
STOP END
ENTER
RETURN
Lect 3 P. 19
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
Write to Screen:
Read from Keyboard:
INFORM
MSG
ERROR
MSG
RESULTS
INPUT
PROMPT
INPUT
INPUT
PROMPT
OPTION
Lect 3 P. 20
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
Read from a File:
Read from a File with a Check for End-of-File:
READ
EOF?
Y
N
READ
EOF?
Y
N
READ WRITE
Lect 3 P. 21
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
Decision or Selection Structure:
General Processing:
QUIT?
Y
N
A<B?
F
T
process
Lect 3 P. 22
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
Definite Loop:
Indefinite Loop:
y
ninit
inc
<= LIM?
do while
index <= limit
y
n
Lect 3 P. 23
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
On-Page Connectors:
Off-Page Connectors:
1
2 2
1
From To
ToFrom
A
A
Lect 3 P. 24
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Flow Charting Symbols
Call (or Invoke) a Subprogram:
subname
Lect 3 P. 25
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Daily Assignment F2
• Problem:
There are a number of apples in a large box
which must be sorted into baskets. An apple is
either a "large red" one, a "small red" one, or a
"green" one.
• Develop a flow chart or algorithm to solve the
problem
Lect 3 P. 26
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Daily Assignment F2
Assumptions:
1. There are 3 empty baskets present and they are
labeled:
#1 – large red, #2 – small red, #3 – green
2. There are counters of some sort present.
3. The person sorting is not color blind and can tell
the difference between large and small apples.
4. Only these three kinds of apples are in the large
box.
Lect 3 P. 27
Engineering H192 - Computer Programming
Winter Quarter
The Ohio State University
Gateway Engineering Education Coalition
Daily Assignment F2
• Are there any unknowns?
• Start with the overall problem
• Develop the steps to solve the problem

More Related Content

What's hot (20)

PPTX
Imaging and Design for Online Environment
Angelito Quiambao
 
PDF
Productivity tools
Angelito Quiambao
 
PPTX
Advanced Word Processing Skills - Empowerment Technologies
Mark Jhon Oxillo
 
PPTX
Computer programming
Vincent Valenzuela
 
PDF
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
PPTX
Collaborative ICT Development - Empowerment Technologies
Mark Jhon Oxillo
 
PDF
An Example of a Quantitative Research Design
dianakamaruddin
 
PPT
Computer programming:Know How to Flowchart
Angelo Tomboc
 
PPTX
Basic Web Design Principles and Elements
EromRamos
 
DOCX
Background example
Novita Dian
 
PDF
Pseudocode & flowchart examples
hayrikk
 
PPT
Writing Chapters 1, 2, 3 of the Capstone Project Proposal Manuscript
Sheryl Satorre
 
PPTX
Algorithm and psuedocode
Mustafa Qureshi
 
PPT
Presentation and analysis and interpretation of data
Lovely Ann Azanza
 
PPTX
[EMPOWERMENT TECHNOLOGIES] - ADVANCED WORD PROCESSING SKILLS
JazzyNF
 
PPTX
Applications of Discrete Structures
aviban
 
PPTX
Empowerment Technology Lesson 1.pptx
Joseph Camarote
 
PPTX
Introduction to Pseudocode
Damian T. Gordon
 
PPT
Chapter 6-THEORETICAL & CONCEPTUAL FRAMEWORK
Ludy Mae Nalzaro,BSM,BSN,MN
 
DOCX
Parts of a Research Paper
Jan Mariel Duayao
 
Imaging and Design for Online Environment
Angelito Quiambao
 
Productivity tools
Angelito Quiambao
 
Advanced Word Processing Skills - Empowerment Technologies
Mark Jhon Oxillo
 
Computer programming
Vincent Valenzuela
 
Algorithm and Programming (Introduction of Algorithms)
Adam Mukharil Bachtiar
 
Collaborative ICT Development - Empowerment Technologies
Mark Jhon Oxillo
 
An Example of a Quantitative Research Design
dianakamaruddin
 
Computer programming:Know How to Flowchart
Angelo Tomboc
 
Basic Web Design Principles and Elements
EromRamos
 
Background example
Novita Dian
 
Pseudocode & flowchart examples
hayrikk
 
Writing Chapters 1, 2, 3 of the Capstone Project Proposal Manuscript
Sheryl Satorre
 
Algorithm and psuedocode
Mustafa Qureshi
 
Presentation and analysis and interpretation of data
Lovely Ann Azanza
 
[EMPOWERMENT TECHNOLOGIES] - ADVANCED WORD PROCESSING SKILLS
JazzyNF
 
Applications of Discrete Structures
aviban
 
Empowerment Technology Lesson 1.pptx
Joseph Camarote
 
Introduction to Pseudocode
Damian T. Gordon
 
Chapter 6-THEORETICAL & CONCEPTUAL FRAMEWORK
Ludy Mae Nalzaro,BSM,BSN,MN
 
Parts of a Research Paper
Jan Mariel Duayao
 

Viewers also liked (17)

PPTX
PROGRAM LOGIC AND FORMULATION
Joland Reambillo
 
PPT
Lecture#2 Computer languages computer system and Programming EC-105
NUST Stuff
 
PPT
C++ for beginners
Salahaddin University-Erbil
 
PPT
Lecture 19 matlab_script&function_files06
Aman kazmi
 
PPTX
Computer programming
Sujay Raj
 
PPTX
Apt programming
Vemulapalli Das
 
DOC
Lab 5 array
mkazree
 
PDF
Use of computer programming in animal diet formulation
Milling and Grain magazine
 
PPSX
DISE - Programming Concepts
Rasan Samarasinghe
 
PPT
NC Programming
Vishnuvardhan Reddy S
 
PPT
Computer Programming- Lecture 6
Dr. Md. Shohel Sayeed
 
PPT
10 Myths for Computer Science
Thanos Hatziapostolou
 
PPTX
Software And Computer Applications for civil engineering
Sameer Nawab
 
PPT
Computer Science Engineering
ITM University, Raipur
 
PPTX
Computer Engineering (Programming Language: Swift)
Sethmi Kachchakaduge
 
PDF
Introduction to cad cam
parabajinkya0070
 
PPT
Embedded System Basics
Dr M Muruganandam Masilamani
 
PROGRAM LOGIC AND FORMULATION
Joland Reambillo
 
Lecture#2 Computer languages computer system and Programming EC-105
NUST Stuff
 
C++ for beginners
Salahaddin University-Erbil
 
Lecture 19 matlab_script&function_files06
Aman kazmi
 
Computer programming
Sujay Raj
 
Apt programming
Vemulapalli Das
 
Lab 5 array
mkazree
 
Use of computer programming in animal diet formulation
Milling and Grain magazine
 
DISE - Programming Concepts
Rasan Samarasinghe
 
NC Programming
Vishnuvardhan Reddy S
 
Computer Programming- Lecture 6
Dr. Md. Shohel Sayeed
 
10 Myths for Computer Science
Thanos Hatziapostolou
 
Software And Computer Applications for civil engineering
Sameer Nawab
 
Computer Science Engineering
ITM University, Raipur
 
Computer Engineering (Programming Language: Swift)
Sethmi Kachchakaduge
 
Introduction to cad cam
parabajinkya0070
 
Embedded System Basics
Dr M Muruganandam Masilamani
 
Ad

Similar to Program Logic Formulation - Ohio State University (20)

PPTX
MODULE1-INTRODUCTION.pptx-COMPUTER PROGRAMING
MarcMiguel2
 
PPTX
Cs1123 2 comp_prog
TAlha MAlik
 
PPT
Algorithms and Flowchart for IGCSE Students
MKKhaing
 
PPTX
Algorithm and flowchart
Elizabeth de Leon Aler
 
PPT
Algorithms and Flowchart.ppt
MsKGowriDhilipkumar
 
PPTX
Problem solving and design
zahid785
 
PPT
Comp102 lec 1
Fraz Bakhsh
 
PPTX
2. Algorithms Representations (C++).pptx
ssuser4d77b2
 
PPTX
Introduction to programming (week 1)
Don Bosco School Manila
 
PPTX
Introduction to programming (week 1)
Don Bosco School Manila
 
PPTX
Flowcharting and Algorithm
Zeinna Belle Desamito
 
PDF
AlgorithmAndFlowChart.pdf
SusieMaestre1
 
PPT
Proble, Solving & Automation
Janani Satheshkumar
 
PPT
UNIT- 3-FOC.ppt
KalaivaniRMECLectCSE
 
PPT
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
ReshuReshma8
 
PPT
Lecture1-Algorithms-and-Flowchart-ppt.ppt
samreen82
 
PPT
Lect1-Algorithms-and-Flowchart PPT presentation
gstagra
 
PPT
Lect1 - Algorithms-and-Flowchart-ppt.ppt
KARMANAYGUPTA1
 
PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Guru Nanak Technical Institutions
 
PDF
Algorithm defination, design & Implementation
Bilal Maqbool ツ
 
MODULE1-INTRODUCTION.pptx-COMPUTER PROGRAMING
MarcMiguel2
 
Cs1123 2 comp_prog
TAlha MAlik
 
Algorithms and Flowchart for IGCSE Students
MKKhaing
 
Algorithm and flowchart
Elizabeth de Leon Aler
 
Algorithms and Flowchart.ppt
MsKGowriDhilipkumar
 
Problem solving and design
zahid785
 
Comp102 lec 1
Fraz Bakhsh
 
2. Algorithms Representations (C++).pptx
ssuser4d77b2
 
Introduction to programming (week 1)
Don Bosco School Manila
 
Introduction to programming (week 1)
Don Bosco School Manila
 
Flowcharting and Algorithm
Zeinna Belle Desamito
 
AlgorithmAndFlowChart.pdf
SusieMaestre1
 
Proble, Solving & Automation
Janani Satheshkumar
 
UNIT- 3-FOC.ppt
KalaivaniRMECLectCSE
 
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
ReshuReshma8
 
Lecture1-Algorithms-and-Flowchart-ppt.ppt
samreen82
 
Lect1-Algorithms-and-Flowchart PPT presentation
gstagra
 
Lect1 - Algorithms-and-Flowchart-ppt.ppt
KARMANAYGUPTA1
 
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Guru Nanak Technical Institutions
 
Algorithm defination, design & Implementation
Bilal Maqbool ツ
 
Ad

More from Reggie Niccolo Santos (15)

PPT
Securing PHP Applications
Reggie Niccolo Santos
 
PDF
Introduction to Web 2.0
Reggie Niccolo Santos
 
PDF
UI / UX Engineering for Web Applications
Reggie Niccolo Santos
 
PPTX
Computability - Tractable, Intractable and Non-computable Function
Reggie Niccolo Santos
 
PDF
Algorithms - Aaron Bloomfield
Reggie Niccolo Santos
 
PDF
Abstract Data Types
Reggie Niccolo Santos
 
PDF
Computational Thinking and Data Representations
Reggie Niccolo Santos
 
PDF
Number Systems
Reggie Niccolo Santos
 
PDF
Introduction to Game Development
Reggie Niccolo Santos
 
PPT
Application Testing
Reggie Niccolo Santos
 
PPT
Application Security
Reggie Niccolo Santos
 
PPT
MySQL Transactions
Reggie Niccolo Santos
 
PPT
MySQL Cursors
Reggie Niccolo Santos
 
PPT
MySQL Views
Reggie Niccolo Santos
 
Securing PHP Applications
Reggie Niccolo Santos
 
Introduction to Web 2.0
Reggie Niccolo Santos
 
UI / UX Engineering for Web Applications
Reggie Niccolo Santos
 
Computability - Tractable, Intractable and Non-computable Function
Reggie Niccolo Santos
 
Algorithms - Aaron Bloomfield
Reggie Niccolo Santos
 
Abstract Data Types
Reggie Niccolo Santos
 
Computational Thinking and Data Representations
Reggie Niccolo Santos
 
Number Systems
Reggie Niccolo Santos
 
Introduction to Game Development
Reggie Niccolo Santos
 
Application Testing
Reggie Niccolo Santos
 
Application Security
Reggie Niccolo Santos
 
MySQL Transactions
Reggie Niccolo Santos
 
MySQL Cursors
Reggie Niccolo Santos
 

Recently uploaded (20)

PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Tally software_Introduction_Presentation
AditiBansal54083
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 

Program Logic Formulation - Ohio State University

  • 1. Lect 3 P. 1 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Structured Engineering Problem Solving and Logic Diagrams Lecture 3
  • 2. Lect 3 P. 2 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition TOOLS FOR PROGRAM DEVELOPMENT • A variety of tools and techniques can be used in the process of program development • Useful for organizing the tasks in problem solving • Many of the tools are focused on the: – development or formulation of algorithms – representation of algorithms – refinement or structuring of algorithms
  • 3. Lect 3 P. 3 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition TOOLS FOR PROGRAM DEVELOPMENT • Top-down design technique – Start with overall function and perform several step-wise refinements • Pseudo code – Artificial and informal language that helps programmers develop algorithms • Logic diagrams – Alternate representations of algorithms including graphic and state representations
  • 4. Lect 3 P. 4 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition TOP-DOWN STEPWISE REFINEMENT • Begin with a single statement that conveys the overall function of the program. This is a complete (but simple) representation of the program. • Divide this "top" statement into a series of smaller tasks and list them in the order in which they must be performed to produce a first refinement.
  • 5. Lect 3 P. 5 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition TOP-DOWN STEPWISE REFINEMENT • Next, refine each of the smaller tasks into yet smaller steps, defining specific "variables" as may be needed in this second refinement. • Continue refinement until algorithm is fully developed. • When combined with pseudo code, writing the program is normally straightforward.
  • 6. Lect 3 P. 6 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example • The Problem: The students in a class have taken their first quiz. The grades (in the range of 0 to 100) are available. Determine the class average on the quiz. • Givens: Grades, Possible range of legitimate grades.
  • 7. Lect 3 P. 7 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example (continued) • Unknowns: How many grades to be averaged? • Assumptions: A "grade" not in the range of expected grades could be used to indicate the that all of the legitimate grades have been entered. (Called "sentinel" or "flag".)
  • 8. Lect 3 P. 8 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example (continued) • Using pseudo code, we begin by representing the top: – Determine the class average for the quiz
  • 9. Lect 3 P. 9 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example (continued) • Next, perform the first refinement: – Determine the class average for the quiz • Initialize variables • Input, sum, and count quiz grades • Calculate and print the class average
  • 10. Lect 3 P. 10 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example (continued) • Next, refine each one of these smaller tasks: – Initialize variables • Initialize a running total to zero • Initialize a grade counter to zero
  • 11. Lect 3 P. 11 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example (continued) Input, sum, and count quiz grades Input the first grade While the user has not entered the "flag" Add this grade into the running total Add one to the grade counter Input next grade (possibly the "flag")
  • 12. Lect 3 P. 12 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Top-Down Example (continued) Calculate and print the class average If the grade counter is not zero Set the class average to the running total divided by the grade counter Print the average Else Print "No grades were entered"
  • 13. Lect 3 P. 13 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Handling Special Cases • Notice that the top-down refinement example included the handling of a "special case". • Many of you are aware of the special treatment that Windows gives to the extreme "special cases" (sometimes called the BSOD or Blue Screen of Death…)
  • 14. Lect 3 P. 14 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Handling Special Cases
  • 15. Lect 3 P. 15 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Some Types of Logic Diagrams • Flow Charts -- graphic representation of an algorithm – an aid to writing the program – no formal standards, but common guidelines • Action Diagrams -- technique for diagramming of control structures of a program – an outline of the computer application – what things happen, when, where, how many times
  • 16. Lect 3 P. 16 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Characteristics of Flow Charts • Useful tool in program development • Not a complete description of program • Not only tool to use • Made before writing the program • Program might differ from flowchart • Only executable statements are shown • Specific equations and tests not included • Every main and sub-program is charted
  • 17. Lect 3 P. 17 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols • The commonly used flowcharting symbols follow • Refer to Section 9 of the H192 "Class Notes" for a more complete description of the various flowcharting symbols normally used
  • 18. Lect 3 P. 18 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols Begin or End a Procedure: "Main Program" "Subprogram" Begin End START BEGIN STOP END ENTER RETURN
  • 19. Lect 3 P. 19 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols Write to Screen: Read from Keyboard: INFORM MSG ERROR MSG RESULTS INPUT PROMPT INPUT INPUT PROMPT OPTION
  • 20. Lect 3 P. 20 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols Read from a File: Read from a File with a Check for End-of-File: READ EOF? Y N READ EOF? Y N READ WRITE
  • 21. Lect 3 P. 21 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols Decision or Selection Structure: General Processing: QUIT? Y N A<B? F T process
  • 22. Lect 3 P. 22 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols Definite Loop: Indefinite Loop: y ninit inc <= LIM? do while index <= limit y n
  • 23. Lect 3 P. 23 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols On-Page Connectors: Off-Page Connectors: 1 2 2 1 From To ToFrom A A
  • 24. Lect 3 P. 24 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Flow Charting Symbols Call (or Invoke) a Subprogram: subname
  • 25. Lect 3 P. 25 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Daily Assignment F2 • Problem: There are a number of apples in a large box which must be sorted into baskets. An apple is either a "large red" one, a "small red" one, or a "green" one. • Develop a flow chart or algorithm to solve the problem
  • 26. Lect 3 P. 26 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Daily Assignment F2 Assumptions: 1. There are 3 empty baskets present and they are labeled: #1 – large red, #2 – small red, #3 – green 2. There are counters of some sort present. 3. The person sorting is not color blind and can tell the difference between large and small apples. 4. Only these three kinds of apples are in the large box.
  • 27. Lect 3 P. 27 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Daily Assignment F2 • Are there any unknowns? • Start with the overall problem • Develop the steps to solve the problem

Editor's Notes

  • #2: Narrator: Lecture 3: Structured engineering problem solving and logic diagrams.
  • #3: Instructor: Many design tools require the programmer to sit down and organize their thoughts in a manner which he or she understands the task to be completed. The methods provided have proved to be useful to programmers. Narrator: A variety of tools and techniques exist that can be used in the process of program development and are useful for organizing tasks in problem solving. Many of these tools are focused on the development of algorithms, representation of these algorithms, and refinement or structuring of the developed algorithms.
  • #4: Instructor: Not necessarily a single tool, but a combination of these tools may be used to formulate a program. Students will become familiar with all of these tools and eventually use a method of program development they are most comfortable with. Narrator: The techniques and tools we will look at are the top-down design technique, pseudo code, and logic diagrams. The technique most commonly used in program development is the top-down design technique. This technique starts with the overall function or problems and is broken down into smaller steps. Pseudo-code is a tool used to develop an algorithm, usually in an informal written language. Logic diagrams are a graphical way to represent an algorithm.
  • #5: Instructor: Top-down refinement is described and example given in the following slides. Narrator: First we will look in-depth at the top-down design technique. As previously stated, first begin with a single statement that conveys the overall function of the program. This is a complete, yet simple representation of the entire program. Then divide this top statement into a series of smaller tasks and list them in the order in which they must be performed. This is the first step-wise refinement.
  • #6: Narrator: Now take each of the smaller tasks and refine these into smaller steps as necessary. Also as it becomes apparent, define specific variables necessary to complete the steps in each task. Continue with this refinement until all tasks are broken into small tasks that can simply be programmed as computer code. Then the algorithm is fully developed. When combining this technique with pseudo-code, writing of the actual program is normally straightforward.
  • #7: Instructor: The following slides illustrate a top-down example where a general solution is broken down into its various tasks and variables. Narrator: Now let’s look at an example we can practice the top-down technique with. Let’s say the students in a class have taken their first quiz. The grades, which can be in the range of 0 to 100 are available. The program’s task is to determine the class average on the quiz. The givens in the problem are the grades input from the user, and the possible range of the legitimate grades.
  • #8: Instructor: This is one example a flag can be used. If a grade outside the range was to not be used to indicate the end of entering grades it should still be checked if it is within a valid range of responses to create fault-tolerant code. Handing this error could be responding with an error to the screen, asking the user to re-input the data, or rounding the data to a valid result. Narrator: Things that could be useful but aren’t known are the number of students in the class, and thus how many grades must be averaged. We can then assume that when a grade is not in the range of expected grades, 0 to 100, that this is an indication that all of the legitimate grades have been entered and the user wishes for the program to display the result. In programming this is called a sentinel or flag.
  • #9: Narrator: In pseudo-code, we can begin be developing an overall statement for the entire program, which will be the top of our top-down refinement. This top is to determine the class average for the quiz.
  • #10: Narrator: Now we can perform the first refinement. This refinement include three smaller steps. The first step is to initialize variables to their desired starting values. Then we input, sum, and count the quiz grades. Finally with the information input and calculated from the second step we can calculate and display the class average.
  • #11: Narrator: Each of these tasks can now be refined into their respective sub-tasks. We need to initialize two variables in this program, the running total of all grades, and the number of grades, or grade counter. In this case we want to initialize both variables to zero.
  • #12: Narrator: Refining the second step one might write pseudo code such as the code shown. We want the user to input a grade, and while the value input is not a sentinel or flag add the grade to the running total of all previous grades. Also we must increment the grade counter by 1, then ask the user to input another value. This section would continue in a loop until the user inputs a flag, or an integer not between 0 and 100.
  • #13: Narrator: Finally the last step covers what must be done after the users enters the flag and the answer must be calculated and displayed to the screen. Various cases may occur in this final step as shown with the if-else structure. If the grade counter is not zero, or the user has actually entered valid grades, then the class average would simply be the running total of the grades divided by the number of grades entered. This can then be printed to the screen. If the user didn’t enter any valid grades, thus entering a flag the first time prompted to enter a grade, the program could instead print and error that no grades were entered, and then exit.
  • #14: Instructor: It is important that students understand when programs are written they must be able to handle all special cases or “exceptions.” Exceptions are found typically in logical evaluations, mathematical expressions, or anywhere input is given by the user. The consequences of not handling all special cases in some manner results in poor performance (demonstrated by Windows’ BSOD for example). Narrator: Notice the if-else structure on the previous slide handled a special case or exception, that in which the user entered no valid grades. Exceptions are found typically in logical evaluations, mathematical expressions, or anywhere input is given by the user. The consequences of not handling all special cases in some manner results in poor performance (demonstrated by Windows’ BSOD for example).
  • #15: Instructor: Special cases not caught by the programmer will eventually be caught by the end-user. Thus thorough testing is necessary to ensure all possible exceptions are handled. One more recently popular method is to release public “beta” copies of software where the public itself tests the programmer’s software and is allowed to provide feedback and problems encountered. This of course can’t be done with all software developed (embedded military, nuclear reactor control, satellite applications for example). Narrator: This is one situation that, unless you are the pilot of a plane, may never expect. Thus it is important to take the mind of the user into account when creating a program or product. Special cases not caught by the programmer will eventually be caught by the end-user. Thus thorough testing is necessary to ensure all possible exceptions are handled. One more recently popular method is to release public “beta” copies of software where the public itself tests the programmer’s software and is allowed to provide feedback and problems encountered. This of course can’t be done with all software developed (such as embedded military, nuclear reactor control, or satellite applications for example).
  • #16: Instructor: The following slides describe flow charts and action diagrams, their similarities, differences, and applications. Narrator: Methods of organizing pseudo-code include logic diagrams. Some types of logic diagrams include flow charts and action diagrams. Flow charts are a graphical representation of an algorithm and are well suited for programmers which can visualize the flow of their programs well. It can be used as an aid to writing the actual program, and there are no formal standards, but some common guidelines exist, which will be discussed in the remainder of this lecture. Action diagrams are a more textual-based technique of diagramming the control structures of a program. The result is an outline which will closely resemble the computer application. It typically explains what things happen, when, where, and how many times. The previous pseudo-code example could be used as a basis for an action diagram.
  • #17: Instructor: Emphasize that the flow chart should be developed before the program is written. Narrator: Flow charts can be a useful tool in program development. They do not typically show a complete description of the program, and are typically used in conjunction with other tools. Flow charts should be made before writing the program, but can also be developed by programmers trying to understand another programmer’s code after it has been written. The final program may differ from the flowchart as only executable statements are shown in the flowchart. Specific equations and tests are also not included. When using flow charts typically every main and sub-program is charted.
  • #18: Instructor: Students will find in their course packets the standard flow chart diagramming symbols and should follow these guidelines when developing a flow chart. The following slides should be covered to ensure all students understand each symbol’s use. Encourage students to ask questions about these slides. Narrator: The following slides show commonly used flowcharting symbols. Please refer to your H192 class notes for these symbols and their descriptions as necessary. We will look over most of these symbols now. Be sure to ask questions about those symbols in which you are unsure of their use since you will be expected to develop a flow chart as part of today’s assignment.
  • #19: Narrator: The beginning and end of a program are normally shown within a rectangle with rounded corners. You may use any common text such as “start”, “begin”, or in the case of a subprogram, “enter” for example. The arrow designates the flow of the program. Normally the arrow will point to the next sequential program block in the flow chart.
  • #20: Instructor: The input from keyboard does not necessarily need an output to screen preceding it at all times. This is the typical way a user enters information to a program though (computer asks for input, user supplies input). When writing to the screen the shape shown here is used. Notice the text doesn’t necessarily need to be the actual text displayed to the screen, only a summary you are familiar with so that when you go back and develop your actual program you know what you wish to place here later. When reading from the keyboard the input symbol is shown below the output symbol. In this case each input from the keyboard is preceded by output to the screen prompting the user to input information. This doesn’t necessarily occur every time, but it common when inputting information from the keyboard.
  • #21: Instructor: The difference in order will change the program’s operation. When a read from a file occurs at some point the program should check that it is not at the end of the file (no more data to input from the file). Typically the read then check method is used more often. This will be described in more detail later when file operations are covered. Narrator: Notice the different symbol when reading and writing to a file as opposed to reading from the keyboard and writing to the screen. Also notice for a read or write the common symbol used is the same as opposed to the previous symbols. When reading from a file you may wish to check if you’ve reached the end of the file. The execution block can be used in conjunction with a selection block in either order shown depending on if you wish to check for the end of file before or after the current read. Notice in the first example if the EOF is true, the program would execute whatever block occurs on the “Y” arrow. If the answer is false, the program will follow the “N” arrow and complete a read from the file.
  • #22: Narrator: The EOF examples on the previous slide use the selection structure. A question is posed inside the block, and depending on if the result is true or false, or yes or no, the program may follow a different arrow and execute different code. General commands may be placed in a rectangle. This commands could be completing some mathematical equation for example.
  • #23: Instructor: A definite loop (for loop) completes a task a certain number of times. Init = initial condition of variable checked, inc = amount variable is incremented, LIM is the upper limit of the variable to continue in the loop in this case. An indefinite loop occurs as long as expression in the box evaluates true. Narrator: Loops can also be represented in a more complex structure which included an embedded selection block. The definite loop completes a task a certain number of times. It begins execution from the top arrow in which a variable is typically initialized to its starting value. Then while this value is less than or equal to a limit the code is executed on the “Y” branch and returns through the left arrow in which the variable is then incremented. This continues until the variable is greater than the limit, and then the “N” branch is followed. The indefinite loop completes a task for an unlimited number of times. Depending on if the logical expression in the box is true or false the loop may continue on the “Y” branch or exit via the “N” branch. This is very similar to the selection block shown on the previous slide.
  • #24: Instructor: In order to keep flow charts as readable as possible one should use the connectors as a last resort. When flow charts get large it may be necessary to use connectors to connect lines from various locations on the page, or to locations on other pages. These should be used as a last resort in order to keep flow charts as readable as possible.
  • #25: Narrator: Finally, to invoke a subprogram the symbol is shown. The subname will be the name of the subprogram which may be on the same page or more likely on a separate page.
  • #26: Instructor: With the assumptions given on the next slide encourage students to develop either a flowchart or action diagram using the to-down approach. Narrator: In today’s assignment you are given the problem of sorting apples in a large box into separate baskets. The apples can be classified as “large red,” “small red,” or “green.” You are to develop logic diagram for the code used to complete this task.
  • #27: Narrator: Some helpful assumptions you may use include the availability of three empty baskets, there are counters of some sort present, the person sorting is not color blind and can tell the difference between large and small apples already, and only three kinds of apples are in the large box that requires sorting.