MISRAK POLYTECHNIC COLLEGE
WDDBA L III
UC DESIGNING
PROGRAM LOGIC
prep by Hana Z 2015 E.C
DESIGNING PROGRAM LOGIC
1.1 Obtaining Design documentation
Introduction
Program logic is the implementation of the program's
requirements and design.
If the design of the application is bad, the program logic
can nevertheless be professionally implemented.
prep by Hana Z 2015 E.C
• Programming logic in general rests on a foundation of
computational logic that is shared by both humans and
machines, which is what we explore as we continue to
interact with new technologies.
• With that in mind, one could develop more specific
definitions of a programming logic having to do with the
basis of a piece of code.
prep by Hana Z 2015 E.C
Generally,
• Program logic is a picture of why and how you believe a
program or a policy will work.
• Program logic demonstrates design & implementation of
competence.
• Program logic provides a chain of reasoning that links
investments with results.
• Program logic is a series of “if-then” relationships that, if
implemented as intended, lead to the desired outcomes.
prep by Hana Z 2015 E.C
OBTAINING DESIGN DOCUMENTATION
• The design document will be the starting point and in many
cases you should, do the design document before doing any of
the actual work of program.
• Having the type of documentation that we are expecting helps
ensure a number of things like; you are doing what the
customer wants; that when you are done, you actually did
what you intended to do; that in case of personnel problems
you project continuity remains; etc.
prep by Hana Z 2015 E.C
• Logic model
• Logic models provide a kind of map for a program or
initiative, helping clarify a program or policy’s destination,
the pathways toward the destination, and markers along the
way. In this consider:
• Where are you going?
• How will you get there?
• What will tell you that you have arrived?
prep by Hana Z 2015 E.C
Logic models provide a simplified picture of the relationships between
the program activities and the desired outcomes of the program. It is
valuable in supporting:
• Program planning.
• Program implementation.
• Program monitoring.
• Program evaluation.
We also use a logic model to:
• Brings detail to broad goals.
• Helps identify gaps in program logic and clarify assumptions.
prep by Hana Z 2015 E.C
A PROGRAM OF REQUIREMENTS
• A specification of requirements or program of requirements is a
document used in a design or procurement process.
• An optimal construction process begins with a thorough
requirements specification, which comprehensively details the
demands and wishes.
• The aim of a program of requirements is to lay down a clear
framework for everyone involved in the project so that everyone
understands which criteria must be met.
prep by Hana Z 2015 E.C
Understanding the programming process
There are six programming phases:
• Understand the problem
• Plan the logic
• Code the program
• Use software to translate the program to
machine language
• Test the program
• Deploy the program into production
prep by Hana Z 2015 E.C
• DETERMINING DESIGN APPROACH
• The method or approach that software engineers
use in solving problems in computer science is
called software development method.
• Another name that is commonly used for the
software development method is called software
life cycle. The software life cycle has the following
components.
prep by Hana Z 2015 E.C
The software life cycle has the following components.
• PRELIMINARY INVESTIGATION
• ANALYSIS
• DESIGN
• IMPLEMENTATION
• TESTING
• MAINTENANCE
prep by Hana Z 2015 E.C
• Preliminary investigation: the purpose of the preliminary
investigation is to determine whether the problem or
deficiency in the current system really exists.
• The project team may re-examine some of the feasibility
aspects of the project. The end result is a decision to proceed
further or to abandon the project.
• DEFINING THE PROBLEM:
• SUGGESTING A SOLUTION
prep by Hana Z 2015 E.C
• DETERMINE WHETHER THE SOLUTION IS FEASIBLE.
• Technical feasibility: whether implementation is possible
with the available or affordable hardware, software and other
technical resources.
• Economic feasibility: whether the benefits of the proposed
solution outweigh the costs.
• Operational feasibility: whether the proposed solution is
desirable within the existing managerial and organizational
framework.
prep by Hana Z 2015 E.C
• ANALYSIS (REQUIREMENT GATHERING): In
the analysis phase end user business requirements are analyzed
and project goals converted into the defined system functions
that the organization intends to develop.
• Try to understand the business in general (activities done,
how it is done, etc)
• Define the specific information requirements, who needs
what information, where, when and how.
• Present a detail description of the functions the new
system must perform.
prep by Hana Z 2015 E.C
IN THIS PHASE WE IDENTIFY:
• Inputs to the problem and their form
• Outputs expected from the solution and their form
• Constraints (what are the limits on the data? E.G. Income
cannot be a negative number)
• Assumptions (problem deals)
• Formulas (e.g. For determining the area. It is length x width)
prep by Hana Z 2015 E.C
THE THREE PRIMARY ACTIVITIES INVOLVED IN
THE ANALYSIS PHASE ARE AS FOLLOWS:
• Gathering business requirement
• Creating process diagrams
• Performing a detailed analysis
prep by Hana Z 2015 E.C
Design phase: in the design phase, we describe the desired
features and operations of the system.
This phase includes business rules, pseudo-code, screen
layouts, and other necessary documentation.
The two primary activities involved in the design phase are as
follows:
• Designing of IT infrastructure
• Designing of system model
prep by Hana Z 2015 E.C
PROGRAM ALGORITHM
• An algorithm is a set of instructions designed to perform a
specific task.
• This can be a simple process, such as multiplying two
numbers, or a complex operation, such as playing a
compressed video file.
• SEARCH ENGINES use proprietary algorithms to display
the most relevant results from their search index for
specific queries.
prep by Hana Z 2015 E.C
• In computer programming, algorithms are often created as
functions.
• These functions serve as small programs that can be referenced
by a larger program.
• For example, an image viewing application may include a library
of functions that each uses a custom algorithm to render different
image file formats.
• An image editing program may contain algorithms designed to
process image data. Examples of image processing algorithms
include cropping, resizing, sharpening, blurring, red-eye
prep by Hana Z 2015 E.C
reduction, and color enhancement.
DESIGNING AN ALGORITHM/ A SOLUTION TO A
PROBLEM
A program is written in order to solve a problem. A solution
to a problem actually consists of two things.
• A way to organize the data.
• Sequence of steps to solve the problem.
prep by Hana Z 2015 E.C
An algorithm is a procedure for solving a problem in terms
of the actions to be executed and the order in which those
actions are to be executed.
An algorithm is,
• A step-by-step sequence of instructions.
• To solve a specific problem.
• In a finite amount of time.
prep by Hana Z 2015 E.C
Algorithm development
• Once the requirements of a program are defined algorithm
development is the next step. An algorithm is procedure for
solving a problem in terms of the action to execute (what
to do) and the order in which these actions are executed
(done). An algorithm needs to be:
• Precise and unambiguous (no ambiguity in any instruction
and in the order of execution),
prep by Hana Z 2015 E.C
• Simple,
• General (1 inch is equal to 2.54cm is not an algorithm, it
has to convert a supplied number of inches)
• Correct,
• Finite (has to have an end),
• Handles all exceptions,
• Efficient in time, memory and other resources,
• Many different methods exist for constructing algorithms,
(an algorithm can be expressed in many ways). Some of
prep by Hana Z 2015 E.C
those methods are narrative, flowchart and pseudo-code.
Flowcharts diagrams
• Flowchart: A flowchart is a graphical representation for an
algorithm.
• It is a diagram consisting of labeled symbols, together with arrows
connecting one symbol to another.
• A flowchart is a type of diagram that represents an algorithm or
process, showing the steps as boxes of various kinds, and their order
by connecting those with arrows.
• This diagrammatic representation can give a step-by-step solution to
a given problem.
prep by Hana Z 2015 E.C
• Flowcharts are used in analyzing, designing, documenting or
A flow chart can be used to:
• Define and analyze processes.
• Build a step-by-step picture of the process for analysis,
discussion, or communication.
• Define, standardize or find areas for improvement in a process,
A picture can say a thousand words! That is why programmers use
flowcharts to display their ideas.
• Flowcharts easily display the way a program naturally flows from
one statement to the next. The following are the symbols used
prep by Hana Z 2015 E.C
when drawing flowcharts.
• The following are the symbols used when drawing flowcharts.
• TERMINAL POINT: MAKES THE BEGINNING OR END OF A PROGRAM.
• PROCESS: INDICATES ANY ARITHMETIC COMPUTATIONS OR DATA MOVEMENT.
• FLOW LINE: IT IS USED TO SHOW THE DIRECTION OF LOGICAL FLOW.
• -----INPUT OR OUTPUT DATA: IT IS USED TO SHOW INPUT OR OUTPUT DATA
• CONNECTOR: CONNECTS SECTIONS OF THE FLOWCHART,
SO THAT THE DIAGRAM CAN MAINTAIN A
• DECISION: INDICATES A YES/NO DECISION TO BE MADE BY THE PROGRAM.
• INTER-PAGE CONNECTOR: USED AS EXIT OR ENTRY FROM A FLOWCHART ON ONE PAGE TO
A
FLOWCHART IN ANOTHER PAGE.
prep by Hana Z 2015 E.C
• PREDEFINED PROCESS: INDICATES A PROCESS DEFINED ELSEWHERE.
• Example 1: A certain company plan to give 10% bonus to
each of its employees at the end of every year. If an employee
has been working for 10 years or more at the company, she/he
is to get an additional birr 100. Draw a flowchart of an
algorithm to calculate and print the bones for a given employee.
• Solution: analysis problem is to compute bonus for employee.
To do so, the salary and number of service years of the
employee must be known. Let the salary be denoted by SAL,
service denoted by YEAR and bonus by BONUS.
• To compute the bonus, we multiply the salary by 10% and
prep by Hana Z 2015 E.C
assign the result to BONUS. Thus, BONUS = SAL*0.10.
• If the employee has served at least 10 years, birr 100 is added to
the computed bonus of the employee and the result is displayed.
Otherwise the originally computed bonus is displayed.
Algorithm: write the operations .
• Read employee’s salary and year of service.
• Calculate the employee’s bonus.
• If years of service is greater than or equal to 10 then increase the
bonus. Otherwise only print the bonus
prep by Hana Z 2015 E.C
A FLOWCHART FOR CALCULATING BONUS
prep by Hana Z 2015 E.C
• EXAMPLE 2. A FLOW CHART FOR CALCULATING INTEREST AMOUNT
prep by Hana Z 2015 E.C
A FLOW CHART FOR CALCULATING INTEREST AMOUNT
• EXAMPLE 3. A program that identifies a larger and
smaller number from two numbers
prep by Hana Z 2015 E.C
Exercise :- Draw the flow chart that calculates grade for
ten students based on the scale: >80-A, >60-B, > 50-C,
>40-D, <40-F.
prep by Hana Z 2015 E.C
Pseudocode
• In computer science and numerical computation, pseudocode is an
informal high-level description of the operating principle of a
computer program or other algorithm.
• An outline of a program, written in a form that can easily be converted
into real programming statements.
• It cannot be compiled nor executed, and there is no real formatting or
syntax rules. It is simply an important step in producing the final code.
• An algorithm is a procedure for solving a problem in terms of the actions
prep by Hana Z 2015 E.C
to be executed and the order in which those actions are to be executed.
• An algorithm is merely the sequence of steps taken to solve
a problem. The steps are normally "sequence," "selection,”
"iteration," and a case-type statement.
• The "selection" is the "if then else" statement, and the
iteration is satisfied by a number of statements, such as the
"while," " do," and the "for," while the case-type statement
is satisfied by the "switch" statement.
Algorithm vs pseudo code
• Both algorithm and pseudo code more or less describe the
prep by Hana Z 2015 E.C
logical sequence of steps that follow in solving a problem
• Pseudo code consists of short readable and formally-styled natural
language that used to explain specific tasks within a program's
algorithm while an algorithm is a group of instructions or a set of
steps applied to solve a particular Problem.
• A pseudo code is a method used to define an algorithm.
• An algorithm is written in a natural language while pseudo code
can be written in high level programming languages.
• Pseudcode cannot be executed on a real computer, but it models
and resembles real programming code, and is written at roughly the
same level of detail.
prep by Hana Z 2015 E.C
• The following pseudo code describes an algorithm which will accept
two numbers from the keyboard and calculate the sum and product
displaying the answer on the monitor screen.
• Solution: use variables sum, product, number1, number2 of type real
display “input two numbers”
Accept number1, number2
Sum = number1 + number2
Print “the sum is “, sum
Product = number1 * number2
prep by Hana Z 2015 E.C
Print “the product is “, product
• Example1: the following pseudo code describes an algorithm which will
accept a number from the keyboard and calculate the sum of n numbers
and design the corresponding flowchart.
Solution: start
Sum = 0
Display “input value n”
Input n
For (I = 1, n, 5)
Input a value
Sum = sum + value
Increment
ENDFOR
Output
prep by Hana Zsum
2015 E.C
StoP
prep by Hana Z 2015 E.C
EXERCISE: 2
Design the pseudo code that sums all the even numbers between 1 and 20
inclusive and then displays the sum. It uses a repeat loop and contains a null
else within the repeat loop.
Start
Sum = 0
count = 1
REPEAT
IF count is even THEN sum = sum + count
count = count + 1
UNTIL count > 20
prep by Hana Z 2015 E.C
DISPLAY sum
prep by Hana Z 2015 E.C
A PSEUDO-CODE THAT CALCULATES GRADE HINT GRADE A>=80, B>=60,
C>=50,D>=40,F<40
• ACCEPT MARK, NAME
• IF MARK>80 THEN
• GRADE A
• ELSE IF MARK >60 THEN
• GRADE B
• ELSE IF MARK >50 THEN
• GRADE C
• ELSE IF MARK >40 THEN
• GRADE D
• ELSE
• GRADE F
prep by Hana Z 2015 E.C
• ENDIF
Exercise calculate grade for ten students based on the scale:
>80-A, >60-B, > 50-C, >40-D, <40-F.
prep by Hana Z 2015 E.C
Continue
prep by Hana Z 2015 E.C
prep by Hana Z 2015 E.C
prep by Hana Z 2015 E.C
prep by Hana Z 2015 E.C
prep by Hana Z 2015 E.C
prep by Hana Z 2015 E.C
prep by Hana Z 2015 E.C
CONT.
<?php
# This is the single line comment
# This is the next line comment
// This is also a single line comment.
?>
In the above example.
*First and second line comments begin with hash(#).
*The third one is begin with(//).
If we check the output of the given example.
Browser show blank page.
Because comments are always non-executable..
prep by Hana Z 2015 E.C