LOGIC FORMULATION Notes
LOGIC FORMULATION Notes
Programming Cycle
Algorithm
❑ Programming Cycle
Pseudocodes
❑ Algorithm
Flowchart
❑ Pseudocodes
Conditional Statements
❑ Flowchart
Looping Constructs
❑ Conditional Statements
❑ Looping Constructs
Programming Cycle
• Problem Definition
• Problem Analysis
• Input
• Output
• Algorithm Development
• Process
• Pseudocodes and Flowcharts
Examples:
• these symbols are connected by lines and arrows to indicate the flow of data
or control from one point to another
Flowchart
• Flowchart Symbols
Decision block
Terminal block
Initialization block
Process block
Connector
Input/Output block
Flow Lines
Flowchart
Flow Lines
• indicated by straight lines with arrows to show the direction of data flow
• the arrowhead is sometimes not shown when the direction of flow is clear
• used to connect blocks by exiting from one and entering another
Flowchart
Terminal block
• ovals or rounded rectangles are used to indicate the start and the end of a
module or program
• an oval is labeled with the name of the module at the start ; the end is
indicated by the word end or stop for the top or Control Module
• a start has no flow lines entering it and only one exiting it; an end or exit has
one flow line entering it but none exiting it
START
END
Flowchart
Initialization block
• used for declaring / initializing variables needed to solve a certain process
• Declaration
• binding of an identifier to the information that relates to it
• stating a variable name to be used
• Initialization
• to set (a starting value of a variable)
• to prepare (a computer or a printer) for use; boot
• to format (a storage medium, such as a disk)
X = 10
Y = 25
Flowchart
Process block
• the rectangle indicates a processing block, for such things as calculations,
opening and closing files, and so forth
• a processing block has one entrance and one exit
X=Y+Z
A = 18
B=A-2
Flowchart
Input/Output block
• the parallelogram indicates input to and output operations
• an I/O block has one entrance and only one exit
Get X Display X
Flowchart
Decision block
• the diamond indicates a decision
• it has one entrance and exactly two exits from the block
• one exit is the action when the resultant is TRUE and the other exit is the
action when resultant is FALSE
T F
Condition
A
Flowchart
Example 1:
• Create a flowchart that displays your age five years from now. The algorithm
should have a variable that is initialized to your current age.
Start
Age = 18
Start Yes No
x > 10?
x=0 x=x+5
Get x Display x
Stop
Flowchart
Example 3:
• Create a flowchart that displays the user’s name, birthday, age, sex, and
phone number. Your flowchart should display the variables with the
following format:
Name: ??????
Age: ?? Start
BDay: ?????????
Sex: ? Name=“”
BDay=“”
Phone#: ??????? Age=0
Sex=‘ ’
Pno=“|”