Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

CMPRG

Programming Logic and Design


INTORODUCTION TO
PROGRAMMING
Algorithms
Learning Objectives:
At the end of the session, students should be able to:
1.Define computer programming;
2.Identify problem solving techniques in
programming.
3.Utilize different tool that aid in logic formulation and
programming
Computer programming
Computer programming is a set of instructions through which one
tells the computer to do the desired task. This set of instructions written
in human readable computer language is called Source Code. Every
program has two parts namely code and data.

Programming - is the process of designing, writing, testing, debugging


/ troubleshooting, and maintaining the source code of computer
programs.
Programming Languages
Programs are set of instructions that are executed
by the computer (CPU) to accomplish certain task.

Programming Languages is used to code


computer programs that instruct the computer to
perform some kind of action. Since computer uses
instructions in a series of 0’s and 1’s, programmer
needs programming languages to communicate
with the computer.
Categories of Programming
Languages
1. Machine Language is the only computer
language that the computer understands because
it is composed of series of 0’s and 1’s which is the
natural language of the computer. It need not be
modified, translated or interpreted before it can be
used by the processor for which it was designed.
Categories of Programming
Languages
2. Symbolic Language
It uses symbols or mnemonics in expressing operations and
operand. It is a language that manipulates on symbols
convenient to human rather than to machines. An example of
this language is assembly language. The example given on
machine language can be coded in assembly language as
ADD 7, BILL
Where ADD is a mnemonic code for addition and 7 is the
number of register whose content is to be added to the
content of memory location named as BILL. Assembly
language program is converted to machine language by the
use of assembler.
Categories of Programming
Languages
3. High-Level Language
Because of the rigid format of machine instruction better
programming languages were developed. Programmers
think of a language that is English –like, easy to
manipulate and could use advance commands, thus high
level languages take the action. Some mathematical
functions that are not supported by some microprocessors
are available in high-level programming language.
Examples of these instructions are the multiply and divide
functions. In low-level language these instructions are
done by repeatedly adding or subtracting numbers for
multiplication and division respectively.
Categories of Programming
Languages
Examples of high-level languages are
– FORTRAN – FORmula TRANslation. It was created to process high-level
mathematics and is designed for the scientist and engineers.
– Pascal – A general-purpose programming language that is suited to a diverse
range of application. It can be used for numeric scientific calculations, as a text
editor, for business and for writing system programs like compilers. Pascal
language developed by Niklaus Wirth and his colleagues was named after Blaise
Pascal, a mathematician, engineer, scientist and religious philosopher.
– COBOL – COmmon Business Oriented Language, It is designed for business
use.
– BASIC – Beginner’s All-purpose Symbolic Instruction Language – the instructions
are simple and easy to use. The language is intended for beginning programmers.
– Visual Basic provides a graphical environment in which the design of forms and
controls can be visualized. Instead of writing lines of codes to design the
appearance of the screen, a prebuilt objects are available and can be used
anytime.
Categories of Programming
Languages
Basic Steps in Designing a
program
1. Problem Definition and Analysis
– Determine the objective of the program. Identify what is
the problem and what is the appropriate solution for the
problem. Ask the question like who will use the program,
what are the inputs and what are the expected outputs of
the program. 
2. Problem-solving Phase (Developing Algorithm)
– Established the logical sequence that is necessary solve
the problem. Create an algorithm that is clear and
simple.
Basic Steps in Designing a
program
3. Code the program
– Choose an appropriate programming language in
coding the program. Write a program that conforms with
the syntax and rules of the chosen programming
language.
4. Testing and Debugging
– Testing the program has two phases: alpha and beta.
• Alpha testing reads through the program searching for logical
errors. Then a diagnostic program is run to search for the
syntax errors.
• Beta testing uses the program in real world to see if there is
bug or any other flaw
Basic Steps in Designing a
program
5. Maintenance and Documentation.
– Start documenting at the beginning of the
program, it will help the present and future user
of the program. Provide a User Documentation
for commercial system, Operator Documentation
for people who run the system and Programmer
Documentation for programmers in charge on
maintaining the program.
Problem Solving Techniques

1. Algorithm - It is a set of logical procedure steps to


solve the problem.
2. Flow Charts - It is a diagrammatic representation of
the sequence of operation for a given problem.
3. Pseudo codes - These are the instructions written
in ordinary English using mathematical and logical
symbols to display the program logic.
4. Decision Tables - A decision table consists of many
independent conditions with several actions, written
in table format to solve the given problem.
Algorithm
The word ‘Algorithm’ is the name of one Persian
author meaning rules of restoration and reduction.
Once the problem is analyzed, its solution is
broken into a number of sample steps. A problem
in a finite sequence is called an algorithm.
Properties of an Algorithm
• Finiteness: An algorithm must always terminate after a
finite number of steps.
• Definiteness: Each step must be clearly defined that
actions carried out must be unambiguous.
• Input: Input should be provided at the beginning of
algorithm.
• Output: Algorithm must produce on or more output.
• Effectiveness: All the operations defined must be
sufficiently basic that they can be done exactly in finite
length of time manually.
Basic Statements Used and
Examples
1. Algorithm always begins with the word ‘Start’
and ends with the word ‘Stop’
2. Step wise solution is written in distinguished
steps. This is as shown in the example
Basic Statements Used and
Examples
3. Input Statement: Algorithm takes one or
more inputs to process. The statements
used to indicate the input is Read a or Input
 
- Let a , b be the names of the Input
- Input a or Read a Input b or Read b
- Where a and b are variable names.
Basic Statements Used and
Examples
4. Output Statements: Algorithm produces
one or more outputs. The statement used
to show the output is output a or print b.
Basic Statements Used and
Examples
5. Assignment Statements: Processing can
be done using the assignment statement.
Example:
Sum=100

Variable Data
Basic Statements Used and
Examples
6. Order in which the steps of an algorithm
are executed is divided in to 3 types
namely
a. Sequential Order
• Each step is performed in serial manner, a step by
step procedure
Basic Statements Used and
Examples
6. Order in which the steps of an algorithm
are executed is divided in to 3 types
namely
a. Sequential Order
• Each step is performed in serial manner, a step by
step procedure
Basic Statements Used and
Examples
b. Conditional Order
Based on fact that the given condition is met or not,
the algorithm selects the next step to do. If
statements are used when decision has to be
made.
Different format of if statements:
Basic Statements Used and
Examples

Here if condition evaluates to true then S1 is


executed otherwise else statements are
executed.
Basic Statements Used and
Examples
Basic Statements Used and
Examples
Basic Statements Used and
Examples
Basic Statements Used and
Examples
c. Iterative Order
Repeats the finite number of steps over and over till
the condition is not meet. Iterative operation is also
called as looping operation.

You might also like