Logic Formulation
and Introduction
to Programming
Learning
Outcomes UNDERSTAND THE
IMPORTANCE OF LOGIC
FORMULATION
DIFFERENTIATE PROGRAM
STRUCTURES
DESIGN SOLUTIONS TO
PROBLEMS
At the end of the
module, the
student must be
able to:
DRAW FLOWCHARTS WRITE PSEUDOCODES CODE USING A
PARTICULAR
PROGRAMMING
LANGUAGE
What is Logic Formulation?
• basic steps
• implement a procedure
• top-down design
• flowcharts
• pseudocodes
Basic Control Structures
Sequence Selection
Unconditional
Repetition
Jump
• Instructions are executed
in the order they are
written
• Provides the building
block for computer
programs.
• Shows a single action or Sequential
one action followed in
order (sequentially) by
another.
• Actions can be inputs,
processes, or outputs.
Example
1) Go to the phone
2) Dial the pizza place
3) Order the pizza
4) Hang up
Sequential Structure
Selection
• Conditional
• Branching
• Decision
• branches off to different instructions depending on whether a condition is
met
• several blocks of program code is executed based on a test for some
condition
• tells the program which action to take, based on a certain condition
• When a condition is evaluated, its result is either true or false
• If the result is true, one action is performed; if the result is false, a
different action is performed
Example
Open your wallet
If you have enough money,
THEN Go to the phone.
Dial the pizza place.
Order the pizza.
Hang up.
ELSE Forget the whole thing.
T
Single
Selection
Structure
Double Selection
Structure
F T
Multiple Selection
Structure
T
F
LOOPING ITERATION
Repetition
PROGRAM REPEATS THE USED WHEN A SET OF
SAME INSTRUCTIONS ACTIONS IS TO BE
PERFORMED REPEATEDLY
Example
DO gobble down pizza
WHILE there is still pizza
OR
DO gobble down pizza
UNTIL none remains
Repetition (while)
F
Repetition
Structure (for)
F
Repetition Structure
(do-while)
F
Unconditional Branch
Program jumps from one Structured programming
place to another forbids this structure
Program Development
Life Cycle
• Implementation phase
• Provides an organized plan for breaking
down the task of program development
into manageable chunks
• Each of which must be successfully
completed before moving on to the next
phase
• Outline of each of the steps used to build
software applications
1. Analyze: Define
the problem
• Besure you understand
what the program should
do.
What the output should be – that
is, exactly what the task should
produce.
Identify the data, or input,
necessary to obtain the desired
output.
Determine how to process the
input to obtain the desired output
– that is, determine what formulas
or ways of doing things can be
used to obtain the output.
2. Design: Plan the solution to the problem
Develop the algorithm Every detail, including obvious
steps, should be considered
3. Choose the interface:
Select and use objects
Obtain Input
Display Output will be displayed
Create objects to receive the input and display
the output
Use appropriate command buttons and menus
to allow the user control
4. Code: Writing using a Programming
Language
• C++
• Visual Basic
• Java
• SYNTAX
Compilation
5. Test and
Typing mistakes Debug.
Locate
and
Algorithm flaws remove
any
errors in
Syntax Error the
program.
Logical Error
• designed for future use
• internal documentation -
statements in the program
that are not executed, but
point out the purposes of 6. Complete the
various parts of the documentation:
program
Organize all the
• detailed description of material that
what the program does and
how to use the program describes the
• instruction manual and on-
program.
line help
• it should take place as the
program is being coded
Flowcharting Symbols
Some Application Flowcharting Symbols
Card File
Direct Access File
Computer Program
Document (such as hard copy from
a computer system
Some Application Flowcharting Symbols
Display
Multi-document
Manual Input
Preparation
Manual Operation
Some Application Flowcharting Symbols
Punched Tape
Collate
Sort
Extract
Some Application Flowcharting Symbols
Merge
Sequential Access Storage
Magnetic Disk
Direct Access Storage
The purpose of an application It reveals how many program are to
flowchart is to use symbols to give be written, what reports or
a general picture of what functions documents are to be produced, and
the computer system should the form and source of the input
perform. data.
Flowcharting
It gives an overall picture of the
application.
Program Flowcharting Symbols
Program Flowcharting Symbols
Program Flowcharting Symbols
Example Problem
• Suppose you are asked to determine the number
of stamps to place on an envelop with the rule or
policy that one stamp will be used for every five
sheets of paper
Problem Analysis
Program Design
Pseudocode & Documentation
Choosing the Interface
• Form Layout
Properties Table
Properties Table
Coding the
Program
Coding the Program
Coding the Program
Coding the Program
Coding the Program