Professional Documents
Culture Documents
Logic Formulation1
Logic Formulation1
Formulation
What is Logic Formulation?
The process of coming out with the basic
steps to implement a procedure in computer
programming. This is usually resorted to
when having top-down design. Flowcharts
and pseudo codes are the two of most
common output of the exercise.
Program Logic Formulation?
-
Basic Control Structures
(logical constructs that specify how
instructions in a program are to be
executed)
Sequence
Selection
Repetition
Unconditional Jump
Sequence
Instructionsare designed to be
executed (performed by the computer)
in the order they are written (i.e., one
after another). This control structure
provides the building block for computer
programs. It is used to show a single
action or one action followed in order
(sequentially) by another. Actions can
be inputs, processes, or outputs.
Example
Go to the phone
Dial the pizza place
Order the pizza
Hang up
Sequence Structure
Selection (conditional, branch, or
decision)
The program branches off to different
instructions depending on whether a condition
is met; or, one of several blocks of program
code is executed based on a test for some
condition. It is used to tell 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
Ifyou have enough money,
THEN Go to the phone.
Dial the pizza place.
Order the pizza.
Hang up.
ELSE Forget the whole thing.
Selection Structure
Single Selection
T
F
Selection Structure ...
Double Selection
F T
Selection Structure ...
Multiple Selection
F
Repetition (looping or iteration)
The program repeats the same
instructions over and over. It is used
when a set of actions is to be
performed repeatedly.
Example
T
F
Repetition Structure ...
For Structure
T
F
Repetition Structure ...
Do/While Structure
T
F
Unconditional Branch
The program jumps from one place
to another. Structured programming
forbids this structure.
Program Development Life Cycle
A part of SDLC’s implementation phase
and 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.
An outline of each of the steps used to build
software applications.
1. Analyze: Define the problem.
Be sure 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 (a logical
sequence of precise steps that solve the
problem). Every detail, including
obvious steps, should appear in the
algorithm.
Translate the algorithm into a logic plan
using any of the popular methods –
flowcharts, pseudocode, top-down charts.
These design tools help the programmer
break a problem into a sequence of small
tasks the computer can perform to solve the
problem. Planning also involves using
representative data to test the logic of the
algorithm by hand to ensure that it is
correct.
3. Choose the interface: Select the
objects (text boxes, command
buttons etc.)
Determine how the input will be obtained
and how the output will be displayed. Then
create objects to receive the input and
display the output. Also, create appropriate
command buttons and menus to allow the
user to control the program.
Card File
Computer Program
Display
Multidocument
Manual Input
Preparation
Manual Operation
Some Application Flowcharting Symbols…
Punched Tape
Collate
Sort
Extract
Some Application Flowcharting Symbols…
Merge
Magnetic Disk
For Two-Dimensional
type array_name[rows][columns];
For Three-Dimensional
type array_name[pages][rows][columns];
Examples
double Department[7];
Department[0]
Department[1]
Department[2]
Department[3]
Department[4]
Department[5]
Department[6]
char Sign[25];
type-specifier array_name[sizeN]…[size1] =
{ value-list }
Examples
Int num[7] = {1,2,3,4,5,6,7}
char str[8]=“Laughter”;
Char str[8]={‘L’,’a’,’u’,’g’,’h’,’t’,’e’,’r’}
int sqrs[7][2]= {
1,1,
2,4,
3,9,
4,16,
5,25,
6,36,
7,49
};
Unsized-Array Initialization
char err1[12]=“read error\n”;
char err2[13]=“write error\n”;
char err3[18]=“cannot open file\n”;