ProgrammingConcepts
ProgrammingConcepts
It is a computer programming in
which the statements are
organized in a specific manner to
minimize error of
misinterpretation.
It enforces a logical structure on
the program being written to
make it more efficient and easier
to understand and modify.
Characteristics of structured
Programming
(Step-wise design)
The breaking down of the system to gain insights
into its compositional subsystems.
The system is divided into subsystems, which also
can be divided into other subsystems and so on.
The idea of this technique is that the sub problems
are easier to solve than the whole problem at once.
The overview of the whole system is first
established and then addresses the specific and
complex issues of the implementation of various
sub-systems.
Top-down is used as a synonym of analysis or
decomposition.
Structured
Programming
Techniques
Top-down
Bottom-up
CASE
ADVANTAGES OF TOP
DOWN DEVELOPMENT
Fewer operation errors since each module is
processed separately.
Less time consuming; each programmer is only
involved in a part of the big project.
Easy to maintain; if there is an error in the output, it is
easy to identify the error generated from which
module of the entire program
Progress can be easily measured; completion of
certain modules indicates how well the project is
coming along.
The processing is optimized; each programmer has to
apply their own knowledge and experience to their
parts (modules)
DISADVANTAGES
The benefit of the solution is not
realised at the early stages.
The implementation cost is likely
to be higher.
BOTTOM-UP DESIGN
In a bottom-up approach the individual
base elements of the system are first
specified in great detail. These
elements are then linked together to
form larger subsystems, which then in
turn are linked, sometimes in many
levels, until a complete top-level
system is formed.
This strategy often resembles a "seed"
model, whereby the beginnings are
small but eventually grow in
complexity and completeness.
ADVANTAGES
This approach is suitable for
smaller programs.
It promotes code re-use; when
you write two or more programs,
many of the instructions you
wrote for the first programs will
be useful for the succeeding ones.
Makes program easier to read
DISADVANTAGES
PROCESS
Calculate the total value (Quantity*Price)
Calculate VAT(12% of total value)
Calculate the Grand total (Total Value + VAT)
OUTPUT
Display the total on the screen.
CHARACTERISTICS OF
ALGORITHMS
an algorithm ends after a fixed number of
steps
each step in an algorithm clealy specifies the
action to be perfomed.
The steps in an algorithm specify basic
operations. These operations could include
mathematical calculations, input/output
functions and logical operations.
The algorithm should accept input data, in a
defined format, before it can be processed by
the given instructions.
An algorithm generates one or more outputs
after the input is processed.
Algorithms can be represented
using natural language, formal
programming languages, pseudo
code or flowchart.
Pseudo code:
1. Pseudo code: is an artificial and informal
language that helps programmers develop algorithms.
It represents an algorithm in English language. It is
used as an alternative to a flowchart. Pseudo code is a
"text-based" detail (algorithmic) design tool. Instead
of using the flow chart, one can use a Pseudocode.
After it has been developed, it can be written in a
high-level language. A number of keywords used in a
Pseudocode are:
begin…end: used to start and finish a Pseudocode.
input (accept): obtain input form a user.
display: this is used to present the result or an output.
If…else, while, etc: used in decision making.
Examples of
pseudocodes:
A pseudocode to calculate the average of
two numbers
Begin
Accept 1st number
Accept 2nd Number
Calculate the average ((num1 +
num2)/2)
Display Average
End
Example 2
IF condition Then
Value or Statement if true
ELSE
Value or statement if false
The Nested If Statement:
IF condition THEN
Statement
ELSE IF condition THEN
Statement
ELSE IF Condition
Statement
Else
Statement
ENDIF
REPETITION CONTROL
STRUCTURE
The repetition control structure is
also known as the looping or
iteration structure.
Looping is the process of
repeatedly executing one or more
steps of an algorithm or program.
It is essential in programming, as
most programs perform
repetitious tasks.
Parts of a loop
1) The loop termination decision - determines when
The loop termination decision - determines when
(under what condition) the loop will be terminated (stopped).
It is essential that some provision in the program be made for
the loop to stop; otherwise, the computer would continue to
execute the loop indefinitely - a loop that doesn't stop is
called an endless loop or infinite loop; when a program gets
stuck in an endless loop, programmers say that the program
is "looping".
(2) The body of the loop - the step or steps of the algorithm
that are repeated within the loop. This may be only one
action, or it may include almost all of the program
statements. Important note: some action must occur within
the body of the loop that will affect the loop termination
decision at some point.
X= x+1
Y = y+3 Output x, y, z
Z = 2x +y
Is x>4? NO
YES
Stop
TRACE TABLE
x y z
For Loop
The for loop execute a given set of
instructions a limited number of times
with little or no changes.
This loop will start with giving a
variable a predefined value and then
keep on executing the body part of the
loop as long as the given condition is
true. Every time the loop is executed,
the variable gets a new value.
A for loop is a another form of a while
loop
The for loop syntax
Repeat
Enter password
Until (Password=QWERTY)
Print “Correct Password. Welcome!”
Programming Terms
A program error is a mistake in a program
A BUG: It is a program error
DEBUGGING: Removing error(s) from the
program
SYNTAX: Rules of a programming
language.
Syntax Error: Results when the
programmer does not follow the
programming language rules
Logical Error: Results when the sequence
of instructions is not correct
Constant: Quantity that does not change
Variable: A quantity that has different values during
execution of program.